两只牛在森林里故意走丢了。农民John开始用他的专家技术追捕这两头牛。你的任务是模拟他们的行为(牛和John)。
追击在10x10的平面网格内进行。一个格子可以是:
一个障碍物, 两头牛(它们总在一起), 或者 农民John. 两头牛和农民John可以在同一个格子内(当他们相遇时),但是他们都不能进入有障碍的格子。
一个格子可以是:
. 空地
........ ......... ........ .......... ....F.... ........ ......... ..C...... ........ ........
牛在地图里以固定的方式游荡。每分钟,它们可以向前移动或是转弯。如果前方无障碍且不会离开地图,它们会按照原来的方向前进一步。否则它们会用这一分钟顺时针转90度。
农民John, 深知牛的移动方法,他也这么移动。
每次(每分钟)农民John和两头牛的移动是同时的。如果他们在移动的时候穿过对方,但是没有在同一格相遇,我们不认为他们相遇了。当他们在某分钟末在某格子相遇,那么追捕结束。开始时,John和牛都面向北方。
每行10个字符,表示如上文描述的地图。
输出一个数字,表示John需要多少时间才能抓住牛们。输出0,如果John无法抓住牛。
*...*..... ......*... ...*...*.. .......... ...*.F.... *.....*... ...*...... ..C......* ...*.*.... .*.*......
49
The Tamworth Two BIO '98 - Richard Forster A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior.
The chase takes place on a 10 by 10 planar grid. Squares can be empty or they can contain:
an obstacle, the cows (who always travel together), or Farmer John. The cows and Farmer John can occupy the same square (when they `meet') but neither the cows nor Farmer John can share a square with an obstacle. Each square is represented as follows:
. Empty square
The cows wander around the grid in a fixed way. Each minute, they either move forward or rotate. Normally, they move one square in the direction they are facing. If there is an obstacle in the way or they would leave the board by walking `forward', then they spend the entire minute rotating 90 degrees clockwise.
Farmer John, wise in the ways of cows, moves in exactly the same way.
The farmer and the cows can be considered to move simultaneously during each minute. If the farmer and the cows pass each other while moving, they are not considered to have met. The chase ends when Farmer John and the cows occupy the same square at the end of a minute.
Read a ten-line grid that represents the initial state of the cows, Farmer John, and obstacles. Each of the ten lines contains exactly ten characters using the coding above. There is guaranteed to be only one farmer and one pair of cows. The cows and Farmer John will not initially be on the same square.
Calculate the number of minutes until the cows and Farmer John meet. Assume both the cows and farmer begin the simulation facing in the `north' direction. Print 0 if they will never meet.
PROGRAM NAME: ttwo INPUT FORMAT Lines 1-10: Ten lines of ten characters each, as explained above
SAMPLE INPUT (file ttwo.in) ........ ......... ........ .......... ....F.... ........ ......... ..C...... ........ ........
OUTPUT FORMAT A single line with the integer number of minutes until Farmer John and the cows meet. Print 0 if they will never meet. SAMPLE OUTPUT (file ttwo.out) 49