A1270 | [COCI-2012_2013-contest4]#6 VOYAGER
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
The Voyager 1 space probe (not to be confused with the Intrepid-class starship) was launched a long time ago, in 1977, and is currently on the verge of leaving our Solar System. As it travels further through space, it has been programmed to leave a radio signal message in any star system it stumbles upon, to mark the probe's path for as long as possible.
Let us assume that a star system can be represented by a rectangular grid with N rows and M columns, dividing the space into N by M equal cells. Each cell can contain a single planet, black hole, or be empty. The probe broadcasts the signal from a pre-determined empty cell, in one of the four axis-aligned directions (“U”-up, “R”-right, “D”-down, “L”-left).
Upon being broadcast, the signal propagates in a straight line along the same row/column until it reaches a planet, where it is deflected by 90 degrees in another direction. There are two kinds of planets, which we will denote by „/“ and „\“. The deflection rules are shown in the image below:
The signal permanently leaves the system upon either entring a cell containing a black hole, or propagating outside the edges of the rectangular grid. It is also known that the signal needs one second to propagate from the current cell to a neighbouring one.
Write a program to determine the direction in which the probe needs to broadcast the signal so that it remains within the system for as long as possible, outputting the optimal direction as well as the resulting longest time. If it is possible for the signal to remain in the system indefinitely, output the message „Voyager“ instead of the required time.
Let us assume that a star system can be represented by a rectangular grid with N rows and M columns, dividing the space into N by M equal cells. Each cell can contain a single planet, black hole, or be empty. The probe broadcasts the signal from a pre-determined empty cell, in one of the four axis-aligned directions (“U”-up, “R”-right, “D”-down, “L”-left).
Upon being broadcast, the signal propagates in a straight line along the same row/column until it reaches a planet, where it is deflected by 90 degrees in another direction. There are two kinds of planets, which we will denote by „/“ and „\“. The deflection rules are shown in the image below:
The signal permanently leaves the system upon either entring a cell containing a black hole, or propagating outside the edges of the rectangular grid. It is also known that the signal needs one second to propagate from the current cell to a neighbouring one.
Write a program to determine the direction in which the probe needs to broadcast the signal so that it remains within the system for as long as possible, outputting the optimal direction as well as the resulting longest time. If it is possible for the signal to remain in the system indefinitely, output the message „Voyager“ instead of the required time.
输入格式
The first line of input contains two positive integers, N (1 ≤ N ≤ 500) and M (1 ≤ M ≤ 500).
Each of the following N lines contains M characters from the set {“/”, “\”, “C”, “.”}, where “/” and “\” represent the two kinds of planets, “C” represents a black hole, and “.” represents an empty cell.
The last line of input contains two positive integers, PR (1 ≤ PR ≤ N) and PC (1 ≤ PC ≤ M), the row and column number, respectively, of the cell where the probe is situated.
Each of the following N lines contains M characters from the set {“/”, “\”, “C”, “.”}, where “/” and “\” represent the two kinds of planets, “C” represents a black hole, and “.” represents an empty cell.
The last line of input contains two positive integers, PR (1 ≤ PR ≤ N) and PC (1 ≤ PC ≤ M), the row and column number, respectively, of the cell where the probe is situated.
输出格式
The first line of output must contain the required optimal broadcast direction (“U”, “R”, “D”, or “L”).
If the solution is not unique, select the first optimal one in the following priority order: first “U”, then “R”, then “D”, and finally “L”.
The second line of output must contain the required longest time (or message).
If the solution is not unique, select the first optimal one in the following priority order: first “U”, then “R”, then “D”, and finally “L”.
The second line of output must contain the required longest time (or message).
输入输出样例
输入 #1
5 5 ../.\ ..... .C... ...C. \.../ 3 3
输出 #1
U 17
输入 #2
input 5 5 ....\ \..\. ./\.. \../C .\../ 1 1
输出 #2
D 12
输入 #3
5 7 /.....\ ../..\. \...../ /.....\ \.\.../ 3 3
输出 #3
R Voyager
In test data worth at least 50% of total points, the signal will not be able to remain in the system
indefinitely.
Clarification of the first example ("*" represents the path of the singal):
start
../.\
.....
.CS..
...C.
\.../
'U' direction
*.***
*.*.*
*C*.*
*..C*
*****
17 seconds
'R' direction
../.\
.....
.C***
...C.
\.../
3 seconds
'D' direction
../.\
.....
.C*..
..*C.
\.*./
3 seconds
'L' direction
../.\
.....
.C*..
...C.
\.../
1 second
indefinitely.
Clarification of the first example ("*" represents the path of the singal):
start
../.\
.....
.CS..
...C.
\.../
'U' direction
*.***
*.*.*
*C*.*
*..C*
*****
17 seconds
'R' direction
../.\
.....
.C***
...C.
\.../
3 seconds
'D' direction
../.\
.....
.C*..
..*C.
\.*./
3 seconds
'L' direction
../.\
.....
.C*..
...C.
\.../
1 second
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted