A9139 | The Evil Temple and the Moving Rocks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test.
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak monsters, you arrived at a square room consisting of tiles forming an $n×n$ grid, surrounded entirely by walls. At the end of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The sound of clashing rocks will awaken the door!Being a very senior adventurer, you immediately realize what this means. In the room next door lies an infinite number of magical rocks. There are four types of rocks:
- '^': this rock moves upwards;
- '<': this rock moves leftwards;
- '>': this rock moves rightwards;
- 'v': this rock moves downwards.
To open the door, you first need to place the rocks on some of the tiles (one tile can be occupied by at most one rock). Then, you select a single rock that you have placed and activate it. The activated rock will then move in its direction until it hits another rock or hits the walls of the room (the rock will not move if something already blocks it in its chosen direction). The rock then deactivates. If it hits the walls, or if there have been already $10^{7}$ events of rock becoming activated, the movements end. Otherwise, the rock that was hit becomes activated and this procedure is repeated.
If a rock moves at least one cell before hitting either the wall or another rock, the hit produces a sound. The door will open once the number of produced sounds is at least $x$ . It is okay for the rocks to continue moving after producing $x$ sounds.
The following picture illustrates the four possible scenarios of moving rocks.
- Moves at least one cell, then hits another rock. A sound is produced, the hit rock becomes activated. 
- Moves at least one cell, then hits the wall (i.e., the side of the room). A sound is produced, the movements end. 
- Does not move because a rock is already standing in the path. The blocking rock becomes activated, but no sounds are produced. 
- Does not move because the wall is in the way. No sounds are produced and the movements end. 
Assume there's an infinite number of rocks of each type in the neighboring room. You know what to do: place the rocks and open the door!
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak monsters, you arrived at a square room consisting of tiles forming an $n×n$ grid, surrounded entirely by walls. At the end of the room lies a door locked with evil magical forces. The following inscriptions are written on the door:
The sound of clashing rocks will awaken the door!Being a very senior adventurer, you immediately realize what this means. In the room next door lies an infinite number of magical rocks. There are four types of rocks:
- '^': this rock moves upwards;
- '<': this rock moves leftwards;
- '>': this rock moves rightwards;
- 'v': this rock moves downwards.
To open the door, you first need to place the rocks on some of the tiles (one tile can be occupied by at most one rock). Then, you select a single rock that you have placed and activate it. The activated rock will then move in its direction until it hits another rock or hits the walls of the room (the rock will not move if something already blocks it in its chosen direction). The rock then deactivates. If it hits the walls, or if there have been already $10^{7}$ events of rock becoming activated, the movements end. Otherwise, the rock that was hit becomes activated and this procedure is repeated.
If a rock moves at least one cell before hitting either the wall or another rock, the hit produces a sound. The door will open once the number of produced sounds is at least $x$ . It is okay for the rocks to continue moving after producing $x$ sounds.
The following picture illustrates the four possible scenarios of moving rocks.
- Moves at least one cell, then hits another rock. A sound is produced, the hit rock becomes activated. 
- Moves at least one cell, then hits the wall (i.e., the side of the room). A sound is produced, the movements end. 
- Does not move because a rock is already standing in the path. The blocking rock becomes activated, but no sounds are produced. 
- Does not move because the wall is in the way. No sounds are produced and the movements end. 
Assume there's an infinite number of rocks of each type in the neighboring room. You know what to do: place the rocks and open the door!
输入格式
The first line will consists of two integers $n$ and $x$ , denoting the size of the room and the number of sounds required to open the door. There will be exactly three test cases for this problem:
- $n=5,x=5$ ;
- $n=3,x=2$ ;
- $n=100,x=10^{5}$ .
All of these testcases are in pretest.
- $n=5,x=5$ ;
- $n=3,x=2$ ;
- $n=100,x=10^{5}$ .
All of these testcases are in pretest.
输出格式
Output $n$ lines. Each line consists of $n$ characters — the $j$ -th character of the $i$ -th line represents the content of the tile at the $i$ -th row and the $j$ -th column, and should be one of these:
- '^', '<', '>', or 'v': a rock as described in the problem statement.
- '.': an empty tile.
Then, output two integers $r$ and $c$ ( $1<=r,c<=n$ ) on the next line — this means that the rock you activate first is located at the $r$ -th row from above and $c$ -th column from the left. There must be a rock in this cell.
If there are multiple solutions, you may output any of them.
- '^', '<', '>', or 'v': a rock as described in the problem statement.
- '.': an empty tile.
Then, output two integers $r$ and $c$ ( $1<=r,c<=n$ ) on the next line — this means that the rock you activate first is located at the $r$ -th row from above and $c$ -th column from the left. There must be a rock in this cell.
If there are multiple solutions, you may output any of them.
输入输出样例
输入 #1
5 5
输出 #1
>...v v.<.. ..^.. >.... ..^.< 1 1
输入 #2
3 2
输出 #2
>;vv ^<. ^.> 1 3
Here's a simulation of the first example, accompanied with the number of sounds produced so far.
 0 sound  1 sound  2 sounds  3 sounds  4 sounds  still 4 sounds In the picture above, the activated rock switches between the '^' rock and the '<' rock. However, no sound is produced since the '^' rock didn't move even a single tile. So, still 4 sound.
 5 sounds At this point, 5 sound are already produced, so this solution is already correct. However, for the sake of example, we will continue simulating what happens.
 6 sounds  7 sounds  still 7 sounds  8 sounds And the movement stops. In total, it produces 8 sounds. Notice that the last move produced sound.
Here's a simulation of the second example:
 0 sound  1 sound  2 sounds Now, the activated stone will switch continuously from one to another without producing a sound until it reaches the $10^{7}$ limit, after which the movement will cease.
In total, it produced exactly 2 sounds, so the solution is correct.
 0 sound  1 sound  2 sounds  3 sounds  4 sounds  still 4 sounds In the picture above, the activated rock switches between the '^' rock and the '<' rock. However, no sound is produced since the '^' rock didn't move even a single tile. So, still 4 sound.
 5 sounds At this point, 5 sound are already produced, so this solution is already correct. However, for the sake of example, we will continue simulating what happens.
 6 sounds  7 sounds  still 7 sounds  8 sounds And the movement stops. In total, it produces 8 sounds. Notice that the last move produced sound.
Here's a simulation of the second example:
 0 sound  1 sound  2 sounds Now, the activated stone will switch continuously from one to another without producing a sound until it reaches the $10^{7}$ limit, after which the movement will cease.
In total, it produced exactly 2 sounds, so the solution is correct.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted