Mr. Frog’s Game(模拟连连看)
Description

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
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
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
Sample Output
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(模拟连连看)的更多相关文章
- 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 ...
- 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 ...
- Mr. Frog’s Game
Mr. Frog’s Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 【CF625E】Frog Fights(模拟)
[CF625E]Frog Fights(模拟) 题面 CF 洛谷 翻译: 有\(n\)只青蛙在一个被分为了\(m\)等分的圆上,对于每份顺时针依次标号. 初始时每只青蛙所在的位置是\(p_i\),速度 ...
- HDU5926 Mr. Frog’s Game
/* HDU5926 Mr. Frog’s Game http://acm.hdu.edu.cn/showproblem.php?pid=5926 杂题水题 * */ #include <cst ...
- HDU5924 Mr. Frog’s Problem
/* HDU5924 Mr. Frog’s Problem http://acm.hdu.edu.cn/showproblem.php?pid=5924 数论 * */ #include <cs ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- HDU 5918 KMP/模拟
Sequence I Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- ABAP术语-Transaction
Transaction 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/19/1112804.html Logical process in ...
- Mybartis逆向工程
Mybartis逆向工程 0.创建工程项目,切记莫用中文,亲测在运行时报错 1.Pom文件,使用mybatis-generator插件 <?xml version="1.0" ...
- Redis支持的五种数据类型
redis支持的五种数据类型: 1.string(字符串) 2.hash(哈希) Redis hash 是一个键值(key=>value)对集合. Redis hash是一个string类型的f ...
- SQL语言简单总结
常用的Sql语言总结: 1. create datebase datebaseName //创建数据库 2. drop datebase datebaseName // ...
- PHP实现长网址与短网址
原文地址:http://www.qqdeveloper.com/detail/29/1.html 什么是长链接.短链接 顾名思义,长链接就是一个很长的链接:短链接就是一个很短的链接.长链接可以生成短链 ...
- CentOS 7.x下升级Python版本到3.x系列(新老版本共存)
由于python官方已宣布2.x系列即将停止支持,为了向前看,我们升级系统的python版本为3.x系列服务器系统为当前最新的CentOS 7.4 1.安装前查看当前系统下的python版本号 # p ...
- ubuntu下的数据库和python存储库安装——MySQL,MongoDB,Redis
MySQL 的安装 sudo apt-get updatesudo apt-get install -y mysql-server mysql-client 启动.关闭和重启MySQL 服务的命令如下 ...
- ruby 批量下载王者荣耀皮肤
主要采用ruby Parallel库提供的多线程方式: require 'unirest' require 'open-uri' require 'parallel' require 'json' u ...
- Java 8 中有趣的操作 Stream
Stream 不是java io中的stream 对象创建 我们没有必要使用一个迭代来创建对象,直接使用流就可以 String[] strs = {"haha","hoh ...
- Java Web开发后端常用技术汇总
技术名称及官网 Spring Framework Spring容器 http://projects.spring.io/spring-framework/ SpringMVC Spring MVC框架 ...