A1186 | [COCI-2008_2009-regional]#6 TABLICA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Ivo has an N×N table. The table has the integers 1 through N2 inscribed in row-major order. The following operations can be done on the table:
1. Rotate a row – all cells in a single row are rotated right, so that the number in the last column moves to the first.
2. Rotate a column – all cells in a single column are rotated down, so that the number in the last row moves to the first.
Ivo occasionally feels the urge to move a number X to cell (R, C) and proceeds as follows:
• While X is not in column C, rotate the row it is in.
• While X is not in row R, rotate the column it is in.
Here is an example of how to move number 6 to cell (3, 4), start from the initial configuration:
Ivo wants to move K numbers one after another. Write a program that calculates the number of rotations needed.
1. Rotate a row – all cells in a single row are rotated right, so that the number in the last column moves to the first.
2. Rotate a column – all cells in a single column are rotated down, so that the number in the last row moves to the first.
Ivo occasionally feels the urge to move a number X to cell (R, C) and proceeds as follows:
• While X is not in column C, rotate the row it is in.
• While X is not in row R, rotate the column it is in.
Here is an example of how to move number 6 to cell (3, 4), start from the initial configuration:
Ivo wants to move K numbers one after another. Write a program that calculates the number of rotations needed.
输入格式
The first line contains two integers N (2 ≤ N ≤ 10000) and K (1 ≤ K ≤ 1000), the table dimension and the number of moves.
Each of the following K lines contains three integers X (1 ≤ X ≤ N2), R and C (1 ≤ R, C ≤ N), the description of one move Ivo wants to make. Ivo does the moves in the order in which they are given.
Each of the following K lines contains three integers X (1 ≤ X ≤ N2), R and C (1 ≤ R, C ≤ N), the description of one move Ivo wants to make. Ivo does the moves in the order in which they are given.
输出格式
Output K lines; for each move, output the number of rotations needed.
输入输出样例
输入 #1
4 1 6 3 4
输出 #1
3
输入 #2
4 2 6 3 4 6 2 2
输出 #2
3 5
输入 #3
5 3 1 2 2 2 2 2 12 5 5
输出 #3
2 5 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted