编程介的小学生 2017-11-25 03:27 采纳率: 20.5%
浏览 658
已采纳

Gem Squares

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.

........
........
........
........
........
..43366.
..121556
44212335

For two neighboring squares, you can exchange the gems.

........
........
........
........
........
..43366.
..111556
44222335

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.

........
........
........
........
........
..43366.
.....556
44...335

If there is no gem under a gem, the gem will fall to the square below.

........
........
........
........
........
.....66.
.....556
44433335

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.

........
........
........
........
........
.....66.
.....556
.......5

........
........
........
........
........
........
.....666
.....555

........
........
........
........
........
........
........
........

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
........
........
........
........
........
..43366.
..121556
44212335

........
........
........
.2......
.2.22...
.1.11...
.2.22...
.2.22...

12121212
21212121
12121212
21212121
12121212
21212121
12121212
21212121

........
........
........
........
........
...96...
...96...
.996966.

0

Sample Output
Yes
Yes
No
Yes

  • 写回答

1条回答 默认 最新

  • threenewbee 2018-03-25 15:55
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数