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

72 人解决,148 人已尝试。

108 份提交通过,共有 427 份提交。

4.9 EMB 奖励。

创建: 13 年,3 月前.

修改: 2 年,11 月前.

最后提交: 6 月,4 周前.

来源: partychen

题目标签
dfs