1162. Tom & Jerry

单点时限: 2.0 sec

内存限制: 256 MB

Tom & Jerry can move in the rectangle(10*10),here is a example:

.....

......*…

..

..........

…*.C....

.....

…*......

..M......*

.....

........

C symbolise the cat

M symbolise the mouse

  • symbolise a obstacle

. symbolise freeland(where tom & jerry can move)

Each second Tom & Jerry can move one step. If they are in the same place we call it “encouter”.

What you should pay attetion is the case that if they “swith”(Tom & Jerry simultaneously move a step which will swith their position,see if Tom is at the point A & Jerry is at the point B at first,and after they move their steps their position turn out to be Tom is at the point B & Jerry is at the point A)IS NOT “encouter”

The principle of their moving:most cases they move directly and if there is a obstacle in his way or the next step will be the border they will use 1 second to turn right.

They face north at the beginning

输入格式

There are many test cases,The frist rows is the case.the next is the each case.Each case have 10 rows!

输出格式

a integer T:the time they “encounter”,if they has never met at all output -1

样例

Input
1
*...*.....
......*...
...*...*..
..........
...*.C....
*.....*...
...*......
..M......*
...*.*....
.*.*......
Output
49

77 人解决,151 人已尝试。

113 份提交通过,共有 440 份提交。

4.8 EMB 奖励。

创建: 17 年,6 月前.

修改: 7 年,2 月前.

最后提交: 2 年,7 月前.

来源: partychen

题目标签
dfs