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 ...
随机推荐
- 复习宝典之Maven项目管理
查看更多宝典,请点击<金三银四,你的专属面试宝典> 第二章:Maven项目管理 Maven是基于项目对象模型(POM project object model),可以通过一小段描述信息(配 ...
- vue 图片压缩 基于cli3 配置
chainWebpack: config => { const imagesRule = config.module.rule('images') imagesRule .use('image- ...
- Apache httpd Server Notes
1. httpd启动.停止以及重启 启动: apachectl –f $PATH_TO_CONF/httpd.conf 停止及重启 apachectl –k stop/restart/graceful ...
- Asp.Net Core链接Mysql数据库
一.新建一个Asp.Net Core WebMVC程序 添加nuget包 Mysql.Data 二.新建一个UserContext类 下面代码中的UserInfo是我自己建的一个实体,里面有俩字段: ...
- thinkphp5 rbac权限
thinkphp 5 rbac权限 一 先创建一个数据库; 例如:创建一个test数据库;然后创建3个 表分别为:test_admin (管理员表), test_role,test_auth. 这个是 ...
- thinkphp5使用workerman定时器定时爬取某站点新闻资讯等内容
1.首先通过 composer 安装workerman,在thinkphp5完全开发手册的扩展->coposer包->workerman有详细说明: #在项目根目录执行以下指令compos ...
- 对Python语法简洁的贴切描述
很多人认为,Python与其他语言相比,具有语法简洁的特点.但这种简洁到底体现在哪些地方,很少有人能说清楚.今天看到一个对这一问题的描述,个人觉得很不错,原文如下: “Python语法主要用来精确表达 ...
- 实验吧web登陆一下好吗
知识点: 万能密码'=' 一道登陆型的SQL注入题目,这种题目一般有四种题型: 1.在username中通过union联查select一个已知字符来与传递的password匹配完成登陆 2.使用万能密 ...
- matlab读取txt文本
textread函数 原文:http://blog.sina.com.cn/s/blog_618af1950100k926.html 文档:https://ww2.mathworks.cn/help/ ...
- 关于verilog中的signed类型
在数字电路中,出于应用的需要,我们可以使用无符号数,即包括0及整数的集合:也可以使用有符号数,即包括0和正负数的集合.在更加复杂的系统中,也许这两种类型的数,我们都会用到. 有符号数通常以2的补码形式 ...