A1377 | [COCI-2020-2021-contest1]#4 Patkice
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Not so long ago, in a distant tropical land, there lived three rubber ducks. One hot summer day while they were lying on the beach, the ducks decided to travel to a nearby island. Since the ducks like adventures, they decided to travel carried by ocean currents in an old black umbrella.
Since the ducks are experienced ocean explorers, before the voyage they will check out a map of ocean currents. On the map, the island where the ducks live is marked by a letter ’o’. The ducks can start their voyage in any of the four directions: north – N, east – E, west – W and south – S.
Ocean currents in these seas move in one of the four directions, and are marked on the map in the following way: west-east ’<’, east-west ’>’, north-south ’v’ and south-north ’^’. When the ducks are located on a cell with a current, they will move one cell in the direction of the current. Ocean currents in these seas are special, as they never lead outside of the map and they don’t form vortexes (places where the ducks would move in circles if they followed the current).
Calm sea is marked by a dot ’.’. If the currents bring the ducks to a cell with calm sea or back to the starting island, they won’t be able to continue the voyage. The island that the ducks want to visit is marked by a letter ’x’.
The ducks don’t want to stop their beach party. They kindly ask you to tell them if it’s possible for them to get to the other island, and if it is, in which direction should they start their voyage. Since one of the ducks gets very seasick, they ask you to choose the direction that will make the voyage as short as possible. If there are multiple directions that yield the same minimal travel time, you should choose the one that is alphabetically first.
Since the ducks are experienced ocean explorers, before the voyage they will check out a map of ocean currents. On the map, the island where the ducks live is marked by a letter ’o’. The ducks can start their voyage in any of the four directions: north – N, east – E, west – W and south – S.
Ocean currents in these seas move in one of the four directions, and are marked on the map in the following way: west-east ’<’, east-west ’>’, north-south ’v’ and south-north ’^’. When the ducks are located on a cell with a current, they will move one cell in the direction of the current. Ocean currents in these seas are special, as they never lead outside of the map and they don’t form vortexes (places where the ducks would move in circles if they followed the current).
Calm sea is marked by a dot ’.’. If the currents bring the ducks to a cell with calm sea or back to the starting island, they won’t be able to continue the voyage. The island that the ducks want to visit is marked by a letter ’x’.
The ducks don’t want to stop their beach party. They kindly ask you to tell them if it’s possible for them to get to the other island, and if it is, in which direction should they start their voyage. Since one of the ducks gets very seasick, they ask you to choose the direction that will make the voyage as short as possible. If there are multiple directions that yield the same minimal travel time, you should choose the one that is alphabetically first.
输入格式
The first line contains integers r and s (3 ≤ r, s ≤ 100), the number of rows and columns of the map.
Each of the next r lines contains s characters from the set ’o<>v^.x’, that represent the map of ocean currents. There will always be exactly one character ’o’ and exactly one character ’x’ on the map. The character ’o’ will never be located in the first or last row nor column.
Each of the next r lines contains s characters from the set ’o<>v^.x’, that represent the map of ocean currents. There will always be exactly one character ’o’ and exactly one character ’x’ on the map. The character ’o’ will never be located in the first or last row nor column.
输出格式
If the ducks can’t reach the other island, print :(.
Otherwise, print :) in the first line. In the second line, print the start direction (N for north, E for east, W for west or S for south).
Otherwise, print :) in the first line. In the second line, print the start direction (N for north, E for east, W for west or S for south).
输入输出样例
输入 #1
6 6 ..>>>v .o^..v .v.<.v .>>^.v .x<<<< ......
输出 #1
:) E
输入 #2
5 5 v<<<< >v.>^ v<.o. >>v>v ..>>x
输出 #2
:) S
In test cases worth 30 points the valid start direction will be unique if it exists.
Clarification of the first two examples:
In the first example, if the ducks start their voyage in any direction but east, they will end up in calm sea
and won’t reach the other island.
In the second example, the ducks will reach the other island if they start by going north or south. They
choose the south way, since it’s shorter.
Clarification of the first two examples:
In the first example, if the ducks start their voyage in any direction but east, they will end up in calm sea
and won’t reach the other island.
In the second example, the ducks will reach the other island if they start by going north or south. They
choose the south way, since it’s shorter.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted