|
||||||||||
Gem SquaresTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 295 Accepted Submission(s): 78 Problem Description You are given a board with 8¡Á8 squares. In each square, there can be either a colored gem or no gem at all. Gems with different colors are represented by different integers. It is guaranteed that there are no more than two consecutive gems with the same color either in a row or in a column, and that there is not any gem above a blank square.
For two neighboring squares, you can exchange the gems.
If there are more than two consecutive gems with the same color in a row or in a column after exchange, these gems will be taken away simultaneously. Note that a gem could be counted both in its row and in its column; refer to the sample test cases for details.
If there is no gem under a gem, the gem will fall to the square below.
After all gems have fallen down to the lowest place, the procedure will be repeated. If there are more than two gems with the same color in a row or in a column, these gems will be taken away simultaneously. Then some gems will fall to the squares below, if there are no gems under those gems.
The procedure will be repeated until there is no gem that can be taken away. Given a board with 8*8 squares, you task is to determine whether all gems can be taken away by a single exchange or not. Input The input consists of several test cases. Each test case will be eight lines, and each line contains eight characters. If in a square there is no gem, ¡®.¡¯ is used to identify it, otherwise an integer k is used to identify the gem¡¯s color, 1¡Ük¡Ü9. There is a blank line between two consecutive test cases. End of input is indicated by a line consisting of 0. Output For each test case, output a single line. If all gems can be taken away by a single exchange, output ¡°Yes¡±; otherwise output ¡°No¡±. Sample Input
Sample Output
Hint You can also exchange a gem with a space in its neighbor. For test case 2, all gems can be taken away by exchanging the leftmost ¡°1¡± and the space on the right. Source | ||||||||||
|