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. SQL语句中生成UUID方法

    SQL语句中生成UUID方法为UUID() 生成带横线UUID: select UUID()                         形如:abaffaca-fd55-11e5-b3d0-d2 ...

  2. ComboBox可搜索下拉框的使用注意事项,简单记录以及我遇到的一些奇怪的bug

    前几天做一个react的项目的时候需要用一个可搜索的下拉框ComboBox,上代码: <ComboBox // className={comboxClassName} items={storeA ...

  3. margin中的bug解决方法

    margin bug问题 : 当做子元素中使用margin-top: 50px;父子元素都会跑出50px, 解决方法: 在父元素中使用下面三种任意一种都可以. 方法一:给父元素加边框 border: ...

  4. go加密算法:非对称加密(三)--Elliptic

    看了2星期的区块链原理与运行机制,加密这里开始变得有些生疏,花了一天时间复习了一些;看到了之前忽略的,也学会了椭圆曲线加密. //基础板:浅显易懂package main import ( " ...

  5. python学习第一天 -----2019年4月15日

    第一周-第06章节-Python3.5-第一个python程序 #!/usr/bin/env python #-*- coding:utf-8 _*- """ @auth ...

  6. 第三节 循环链表的Go语言实现

    一.什么是循环链表 循环链表的节点形成一个圈.把单链表的尾巴指向开头形成单循环链表.把双向链表的尾巴与开头链接起来就形成双向循环链表.使用循环链表可以不断的绕圈寻找所需要的数据,而不需要像单链表那样每 ...

  7. LVS那些事

    1998年,章文嵩博士成立了Linux Virtual Server的自由软件项目,进行Linux服务器集群的开发工作. 他的目标是:使用集群技术和Linux操作系统实现一个高性能.高可用的服务器,它 ...

  8. 使用idea上传项目到gitHub

    上传项目到gitHub 创建好后开始提交本地项目代码如图: 选中VCS选中图中的按钮如图所示: 然后再选中Src点中add按钮如图所示: 然后点中commit Directory后 打开终端进行项目根 ...

  9. .net core 中后台获取前台 数据(post)的方法

    [HttpPost] public async Task<JsonResult> EditPoint() { Stream reqStream = Request.Body; string ...

  10. zabbix经常报警elasticsearch节点TCP连接数过高问题

    单服务器最大tcp连接数及调优汇总 单机最大tcp连接数 网络编程 在tcp应用中,server事先在某个固定端口监听,client主动发起连接,经过三路握手后建立tcp连接.那么对单机,其最大并发t ...