东黑布衣,流浪幽燕。 真诚善良,值得信赖。
全部博文(327)
分类: BSD
2006-07-26 21:35:09
The Samsung S/W Company plans to develop a game using mirrors on
a nxn 2-dimensional grid. Each mirror is a two-way mirror and ha
s only two directions as follows.
In the game, when a laser beam starts at (0, 0) in right directi
on, they need to count the number of times the beam hits a mirro
r until it hits a wall (boundary) of the grid.
[Example] In the following configuration, the beam hits mirrors
7 times until it hits the upper wall.
[Sample Input]
4 // Total number of test cases 10 // n = 10,Test Case #1 0 0 0 0 0 0 0 2 0 0 // 0 : empty cell, 1 : [Direction 1], 2 : [Direction 2] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 2 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 5 // Test Case #2 0 2 0 0 0 0 0 0 0 0 0 2 0 1 0 2 0 0 1 0 0 2 0 0 0 10 // Test Case #3 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 2 1 0 0 0 2 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 2 0 0 0 1 0 0 2 0 0 0 0 1 0 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 1 10 // Test Case #4 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 1 0 0 0 0 0 0 0 2 0 1 0 0 0 2 1 0 2 0 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 |
[Sample Output]
#1 7 #2 3 #3 3 #4 4 |