博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mr. Frog’s Game(模拟连连看)
阅读量:5306 次
发布时间:2019-06-14

本文共 2361 字,大约阅读时间需要 7 分钟。

Description

One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese). 
In this game, if you can draw at most three horizontal or vertical head-and-tail-connected lines over the empty grids(the lines can be out of the whole board) to connect two non-empty grids with the same symbol or the two non-empty grids with the same symbol are adjacent, then you can change these two grids into empty and get several more seconds to continue the game. 
Now, Mr. Frog starts a new game (that means there is no empty grid in the board). If there are no pair of grids that can be removed together,Mr. Frog will say ”I’m angry” and criticize you. 
Mr. Frog is battle-scarred and has seen many things, so he can check the board in a very short time, maybe one second. As a Hong Kong Journalist, what you should do is to check the board more quickly than him, and then you can get out of the room before Mr. Frog being angry. 
 

Input

The first line contains only one integer T ($T \leq 500$), which indicates the number of test cases. 
For each test case, the first line contains two integers n and m ($1 \leq n,m \leq 30$). 
In the next n lines, each line contains m integers,  j-th number in the i-th line means the symbol on the grid(the same number means the same symbol on the grid). 
 

Output

For each test case, there should be one line in the output. 
You should output “Case #x: y”,where x is the case number(starting from 1), and y is a string representing the answer of the question. If there are at least one pair of grids that can be removed together, the y is “Yes”(without quote), else y is “No”.
 

Sample Input

2
3 3
1 2 1
2 1 2
1 2 1
3 3
1 2 3
2 1 2
3 2 1
 

Sample Output

Case #1: Yes
Case #2: No

 

Hint

first sample can be explained as below.
 

 

 题目意思:这是一个连连看游戏,只要矩阵内部有两个相同图案相邻或者外围(四条最外边)上只少有两个相同的图案,就可以进行一次消去,问能否进行一次消去。

 解题思路:大致分为两种情况:1矩阵内部有相邻的图案,2矩阵外围上至少有两个相同的图案。直接暴力遍历这个矩阵即可。

 

1 #include
2 #include
3 int main() 4 { 5 int t,i,j,n,m,flag,count=1; 6 int a[32][32]; 7 scanf("%d",&t); 8 while(t--) 9 {10 flag=0;11 12 memset(a,0,sizeof(a));13 scanf("%d%d",&n,&m);14 for(i=1; i<=n; i++)15 {16 for(j=1; j<=m; j++)17 {18 scanf("%d",&a[i][j]);19 }20 }21 for(i=1; i

 

转载于:https://www.cnblogs.com/wkfvawl/p/9049231.html

你可能感兴趣的文章
博弈论
查看>>
Redis sentinel & cluster 原理分析
查看>>
我的工作习惯小结
查看>>
把word文档中的所有图片导出
查看>>
浏览器的判断;
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
Leetcode 589. N-ary Tree Preorder Traversal
查看>>
机器学习/深度学习/其他开发环境搭建记录
查看>>
xml.exist() 实例演示
查看>>
判断是否为空然后赋值
查看>>
zabbix监控日志文件
查看>>
正则表达式
查看>>
pip install torch on windows, and the 'from torch._C import * ImportError: DLL load failed:' s...
查看>>
环套树
查看>>
java基础(一):我对java的三个环境变量的简单理解和配置
查看>>
arcgis api 4.x for js 结合 Echarts4 实现散点图效果(附源码下载)
查看>>
YTU 2625: B 构造函数和析构函数
查看>>
apache自带压力测试工具ab的使用及解析
查看>>
C#使用Xamarin开发可移植移动应用(2.Xamarin.Forms布局,本篇很长,注意)附源码
查看>>
jenkins搭建
查看>>