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矩阵外围上至少有两个相同的图案。直接暴力遍历这个矩阵即可。

 #include<stdio.h>
#include<string.h>
int main()
{
int t,i,j,n,m,flag,count=;
int a[][];
scanf("%d",&t);
while(t--)
{
flag=; memset(a,,sizeof(a));
scanf("%d%d",&n,&m);
for(i=; i<=n; i++)
{
for(j=; j<=m; j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=; i<m; i++)
{
for(j=i+; j<=m; j++)
{
if(a[][i]==a[][j]||a[n][i]==a[n][j])
{
flag=;
}
}
if(flag==)
{
break;
}
}
for(i=; i<n; i++)
{
for(j=i+; j<=n; j++)
{
if(a[i][]==a[j][]||a[i][m]==a[j][m])
{
flag=;
}
}
if(flag==)
{
break;
}
}
for(i=; i<=n; i++)
{
for(j=; j<=m; j++)
{
if(i!=n&&a[i][j]==a[i+][j])
{
flag=;
}
if(j!=m&&a[i][j]==a[i][j+])
{
flag=;
}
}
if(flag==)
{
break;
}
}
if(flag==)
{
printf("Case #%d: Yes\n",count);
count++;
}
else
{
printf("Case #%d: No\n",count);
count++;
}
}
return ;
}

Mr. Frog’s Game(模拟连连看)的更多相关文章

  1. HDU 5926 Mr. Frog's Game 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  2. HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. Mr. Frog’s Game

    Mr. Frog’s Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. 【CF625E】Frog Fights(模拟)

    [CF625E]Frog Fights(模拟) 题面 CF 洛谷 翻译: 有\(n\)只青蛙在一个被分为了\(m\)等分的圆上,对于每份顺时针依次标号. 初始时每只青蛙所在的位置是\(p_i\),速度 ...

  5. HDU5926 Mr. Frog’s Game

    /* HDU5926 Mr. Frog’s Game http://acm.hdu.edu.cn/showproblem.php?pid=5926 杂题水题 * */ #include <cst ...

  6. HDU5924 Mr. Frog’s Problem

    /* HDU5924 Mr. Frog’s Problem http://acm.hdu.edu.cn/showproblem.php?pid=5924 数论 * */ #include <cs ...

  7. Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟

    E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...

  8. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  9. HDU 5918 KMP/模拟

    Sequence I Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

随机推荐

  1. Mac 字典扩充包 包括 app

    https://pan.baidu.com/s/1htKUaiWZFZJGO6w9azsbsg

  2. Linux下安装 Redis

    一.部署前准备 1.首先上官网下载Redis 最新稳定的压缩包 2.通过远程管理工具,将压缩包拷贝到Linux服务器中,执行解压操作 [root@CentOS6 ~]# tar zxvf redis- ...

  3. 纯js轮播图练习-2,js+css旋转木马层叠轮播

    基于css3的新属性,加上js的操作,让现在js轮播图花样越来越多. 而现在出现的旋转木马层叠轮播的轮播图样式,却是得到了很多人都喜爱和投入使用. 尤其是在各大软件中,频繁的出现在大家的眼里,在web ...

  4. PHP防止数字太大转化为科学计数法的方法

    PHP当数字在20位或者20位以上时,会转化为科学计数法 例子: <?phpecho 11111111111111111111; ?> 解决方法可以使用php函数number_format ...

  5. python学习——面向对象的三大特性

    一.继承 继承是一种创建新类的方式,在python中,新建的类可以继承一个或多个父类,父类又可称为基类或超类,新建的类称为派生类或子类. 1.python中类的继承分为:单继承和多继承 class P ...

  6. Leecode刷题之旅-C语言/python-217存在重复元素

    /* * @lc app=leetcode.cn id=217 lang=c * * [217] 存在重复元素 * * https://leetcode-cn.com/problems/contain ...

  7. C++编译错误杂记

    目录 2018年12月23日 error: no matching function for call to ××× 2018年12月10日 error: expected ')' before '* ...

  8. 贪心算法之Dijkstra

    贪心算法的主要思想就是通过不断求解局部最优解,最后求出最优解或者最优解的近似值,不能保证一定为最优解. Dijistra算法,选取没有选择过的点到已经选择过得点组成的集合中最短的距离的点.然后更新已选 ...

  9. 决策树算法之ID3与C4.5的理解与实现

    github:代码实现 本文算法均使用python3实现 1. 决策树   决策树(decision tree)是一种基本的分类与回归方法(本文主要是描述分类方法),是基于树结构进行决策的,可以将其认 ...

  10. day 1 安装pygame

    1.稀里糊涂装上了 参考博客:http://blog.csdn.net/sinat_40043477/article/details/78276460