Mr. Frog’s Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 312    Accepted Submission(s): 209

Problem 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≤500

), which indicates the number of test cases.

For each test case, the first line contains two integers n and m (1≤n,m≤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.

 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5932 5931 5930 5928 5927 
/*
这个题可以搜索,但是30*30完全可以暴力
*/
#include<bits/stdc++.h>
using namespace std;
int pa[][];
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
int T,nl = ,N,M,i,j,pl;
scanf("%d",&T);
while(T--)
{
pl = ;
scanf("%d%d",&N,&M);
for(i = ; i <= N; i++)
for(j = ; j <= M; j++)
scanf("%d",&pa[i][j]);
for(i = ; i < M ; i++)///判断边上是不是有相同的
{
for(j = i + ; j <= M ; j++)
if((pa[][i] == pa[][j]) || (pa[N][i] == pa[N][j]))
pl = ;
if(pl) break;
}
if(!pl)
{
for(i = ; i < N ; i++)///判断是不是有相连的有相同的
{
for(j = i + ; j <= N ; j++)
if((pa[i][] == pa[j][]) || (pa[i][M] == pa[j][M]))
pl = ;
if(pl) break;
}
if(!pl)
{
for(i = ; i <= N ; i++)///判断是不是有相连的有相同的
{
for(j = ; j <= M ; j++)
{
if(i!= N && pa[i][j] == pa[i + ][j]) pl = ;
if(j!= M && pa[i][j] == pa[i][j + ]) pl = ;
}
if(pl) break;
}
}
}
if(pl)
printf("Case #%d: Yes\n",++nl);
else
printf("Case #%d: No\n",++nl);
}
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(模拟连连看)

    Description One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese). In this game, if you ...

  4. HDU5926 Mr. Frog’s Game

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

  5. HDU5924 Mr. Frog’s Problem

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

  6. hdu5926Mr. Frog’s Game

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

  7. hdu5924Mr. Frog’s Problem

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

  8. 10.6 CCPC northeast

    1001 Minimum's Revenge 点的编号从 1 到 n ,u  v 的边权是 LCM(u,v) ,求这个图的最下生成树 搞成一颗以 1 为 根 的菊花树 ---------------- ...

  9. 2016 长春东北赛---Coconuts(离散化+DFS)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5925 Problem Description TanBig, a friend of Mr. Frog ...

随机推荐

  1. Atlas框架介绍集成(一)

    Atlas是什么? Atlas是一个Android客户端容器框架,主要提供了组件化.动态性.解耦化的支持.支持在编码期.Apk运行期以及后续运维修复期的各种问题. 在工程期,实现工程独立开发,调试功能 ...

  2. Highway Networks Pytorch

    导读 本文讨论了深层神经网络训练困难的原因以及如何使用Highway Networks去解决深层神经网络训练的困难,并且在pytorch上实现了Highway Networks. 一 .Highway ...

  3. Ubuntu升级出现/boot空间不足解决

    经常升级Linux内核,导致更新时警告/boot分区空间不足.这是以为多次升级内核后,导致内核版本太多,清理一下没用的内核文件就行了.命令如下: zht@zht-Ubuntu:~$ dpkg -l ' ...

  4. spring-mvc List及数组的配置接收

    数组接收 前台传递数组id 后台接收方式: public WebReturnObject deleteBatch(@RequestParam("id[]") String[] id ...

  5. 【Spring】面向切面之AOP

    前言 前面已经讲解了bean的装配技术,接着学习Spring中另外一个核心概念:切面. 面向切面 面向切面编程 切面能够帮助模块化横切关注点,横切关注点可以被描述为影响应用的功能,如为业务添加安全和事 ...

  6. 支持向量机(Support Vector Machine)-----SVM之SMO算法(转)

    此文转自两篇博文 有修改 序列最小优化算法(英语:Sequential minimal optimization, SMO)是一种用于解决支持向量机训练过程中所产生优化问题的算法.SMO由微软研究院的 ...

  7. 像 npm 一样在 Andriod 项目中引入 Gradle 依赖

    一.前言 作为 Android 开发人员,有没有羡慕过 node.js 的导入三方库的方式,node.js 社区为开发者准备了一个快速可靠的依赖管理库.这样的依赖管理库,让 node.js 导入依赖库 ...

  8. ES6的变量解构赋值

      前  言 ES6 解构赋值: ES6允许按照一定模式从数组和对象中提取值,然后对变量进行赋值,这被称为解构. 1.1 数组的结构赋值 1.1.1基本用法 JS中,为变量赋值直接指定.例如下面代码: ...

  9. 吾八哥学Python(三):了解Python基础语法(上)

    学习一门开发语言首先当然是要熟悉它的语法了,Python的语法还算是比较简单的,这里从基础的开始了解一下. 标识符1.第一个字符必须是字母表中字母或下划线'_'.2.标识符的其他的部分有字母.数字和下 ...

  10. win10 UWP 圆形等待

    看到一个圆形好像微软ProgressRing 我们可以用自定义控件 按ctrl+shift+a 用户控件 我们可以用Rectangle做圆形边 只要Rectangle RadiusX>0圆角 因 ...