轻量级前端框架助力开发者提升项目效率与性能
808
2022-10-21
Codeforces Round #354 (Div. 2) D (BFS)
D. Theseus and labyrinth
栏
D. Theseus and labyrinth
time limit per test 3 seconds
memory limit per test 256 megabytes
input standard input
output standard output
Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1 × 1.
Each block of the labyrinth has a button that rotates all blocks 90 degrees clockwise. Each block rotates around its center and doesn't change its position in the labyrinth. Also, each block has some number of doors (possibly none). In one minute, Theseus can either push the button in order to rotate all the blocks 90 degrees clockwise or pass to the neighbouring block. Theseus can go from block A to some neighbouring block B only if block A has a door that leads to block B and block B has a door that leads to block A.
Theseus found an entrance to labyrinth and is now located in block (xT, yT) — the block in the row xT and column yT. Theseus know that the Minotaur is hiding in block (xM, yM)
Theseus is a hero, not a programmer, so he asks you to help him.
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in labyrinth, respectively.
Each of the following n lines contains m
«+» means this block has 4«-» means this block has 2«|» means this block has 2«^» means this block has 1«>» means this block has 1«<» means this block has 1«v» means this block has 1«L» means this block has 3«R» means this block has 3«U» means this block has 3«D» means this block has 3«*» means this block is a wall and has no doors.
Left, right, top and bottom are defined from representing labyrinth as a table, where rows are numbered from 1 to n from top to bottom and columns are numbered from 1 to m
Next line contains two integers — coordinates of the block (xT, yT) (1 ≤ xT ≤ n, 1 ≤ yT ≤ m), where Theseus is initially located.
Last line contains two integers — coordinates of the block (xM, yM) (1 ≤ xM ≤ n, 1 ≤ yM ≤ m), where Minotaur hides.
It's guaranteed that both the block where Theseus starts and the block where Minotaur is hiding have at least one door. Theseus and Minotaur may be initially located at the same block.
Output
If Theseus is not able to get to Minotaur, then print -1
Examples
input
2 2+**U1 12 2
output
-1
input
2 3<><><>1 12 1
output
4
Note
Assume that Theseus starts at the block (xT, yT) at the moment 0.
题解;
在一幅n*m的地图,地图上有很多标志,然后每秒钟可以穿过门,也可以使得所有门都顺时针转动90°
如果你要从A到B,那么从B也必须能够到达A,问从起点到终点的最短时间是多少?
BFS撸一波。。
AC代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~