A1220 | [COCI-2011_2012-contest1]#4 SKAKAC
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko and Slavko are playing the popular new game known as The Knight. Mirko places a knight chess piece on an NxN chessboard and, with Slavko blindfolded, makes exactly T moves, one per second.
After that, Slavko must guess the final position of the knight in order to win.
The chessboard in this game is unusual in that each square is blocked part of the time. More precisely, each square is labelled by a positive integer. A square labelled by number K is clear only during seconds 0, K, 2K, 3K etc; it is blocked at all other times. The knight can, of course, occupy a square only while the square is clear.
The game begins in second
0. In each second Mirko must make a move (selecting one of 8 possible Lshaped moves, two squares in one direction and one square in the other, as per standard chess rules), provided that the destination square is not blocked during the next second. Help Slavko by writing a program to calculate all possible squares that the knight can possibly occupy after T moves.
After that, Slavko must guess the final position of the knight in order to win.
The chessboard in this game is unusual in that each square is blocked part of the time. More precisely, each square is labelled by a positive integer. A square labelled by number K is clear only during seconds 0, K, 2K, 3K etc; it is blocked at all other times. The knight can, of course, occupy a square only while the square is clear.
The game begins in second
0. In each second Mirko must make a move (selecting one of 8 possible Lshaped moves, two squares in one direction and one square in the other, as per standard chess rules), provided that the destination square is not blocked during the next second. Help Slavko by writing a program to calculate all possible squares that the knight can possibly occupy after T moves.
输入格式
The first line of input contains two positive integers, N (3 ≤ N ≤ 30), the size of the chessboard, and T (1 ≤ T ≤ 1 000 000), the number of moves that Mirko will make.
The second line of input contains two positive integers X and Y (1 ≤ X, Y ≤ N), the row and column indices of the knight’s starting square selected by Mirko.
The next N lines each contain N positive integers less than 109 (one billion), the values of K for the corresponding chessboard squares.
The second line of input contains two positive integers X and Y (1 ≤ X, Y ≤ N), the row and column indices of the knight’s starting square selected by Mirko.
The next N lines each contain N positive integers less than 109 (one billion), the values of K for the corresponding chessboard squares.
输出格式
The first line of output must contain the nonnegative integer M, the number of squares that the knight can possibly occupy after T moves.
The next M lines must contain indices of those squares, sorted by increasing row index, with cells in the same row sorted by increasing column index.
The next M lines must contain indices of those squares, sorted by increasing row index, with cells in the same row sorted by increasing column index.
输入输出样例
输入 #1
3 2 1 1 1 3 2 2 3 2 3 1 1
输出 #1
2 1 1 1 3
输入 #2
5 6 2 3 4 5 3 2 3 1 3 4 3 1 3 4 1 3 2 4 4 2 1 3 4 6 4 9 2
输出 #2
5 1 4 2 1 2 5 4 5 5 2
输入 #3
3 3 2 2 3 6 4 2 2 5 1 3 7
输出 #3
0
In test cases worth 40% of total points, the number of moves T will be less than 50 000.
First sample description: The state of the chessboard in each second is shown below. Clear cells are
denoted by ‘.’, blocked cells by ‘#’, and possible locations of the knight by ‘K’.
First sample description: The state of the chessboard in each second is shown below. Clear cells are
denoted by ‘.’, blocked cells by ‘#’, and possible locations of the knight by ‘K’.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted