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 
  1. /*
  2. 这个题可以搜索,但是30*30完全可以暴力
  3. */
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. int pa[][];
  7. int main()
  8. {
  9. //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
  10. int T,nl = ,N,M,i,j,pl;
  11. scanf("%d",&T);
  12. while(T--)
  13. {
  14. pl = ;
  15. scanf("%d%d",&N,&M);
  16. for(i = ; i <= N; i++)
  17. for(j = ; j <= M; j++)
  18. scanf("%d",&pa[i][j]);
  19. for(i = ; i < M ; i++)///判断边上是不是有相同的
  20. {
  21. for(j = i + ; j <= M ; j++)
  22. if((pa[][i] == pa[][j]) || (pa[N][i] == pa[N][j]))
  23. pl = ;
  24. if(pl) break;
  25. }
  26. if(!pl)
  27. {
  28. for(i = ; i < N ; i++)///判断是不是有相连的有相同的
  29. {
  30. for(j = i + ; j <= N ; j++)
  31. if((pa[i][] == pa[j][]) || (pa[i][M] == pa[j][M]))
  32. pl = ;
  33. if(pl) break;
  34. }
  35. if(!pl)
  36. {
  37. for(i = ; i <= N ; i++)///判断是不是有相连的有相同的
  38. {
  39. for(j = ; j <= M ; j++)
  40. {
  41. if(i!= N && pa[i][j] == pa[i + ][j]) pl = ;
  42. if(j!= M && pa[i][j] == pa[i][j + ]) pl = ;
  43. }
  44. if(pl) break;
  45. }
  46. }
  47. }
  48. if(pl)
  49. printf("Case #%d: Yes\n",++nl);
  50. else
  51. printf("Case #%d: No\n",++nl);
  52. }
  53. return ;
  54. }

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. AngularJS 1.3中的一次性数据绑定(one-time bindings)

    点击查看AngularJS系列目录 谈谈AngularJS 1.3中的一次性数据绑定(one-time bindings) 不久之前,AngularJS 1.3版本正式发布,其中添加了很多的性特性,同 ...

  2. Java钉钉开发_02_免登授权(身份验证)(附源码)

    源码已上传GitHub: https://github.com/shirayner/DingTalk_Demo 一.本节要点 1.免登授权的流程 (1)签名校验 (2)获取code,并传到后台 (3) ...

  3. hdu1251字典树递归算法

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  4. tesseract-ocr字库训练图文讲解

    第一步合成图片集 你需要把使用jTessBoxEditor工具把你的训练素材及多张图片合并成一张tif格式的图片集 第二步  生成box文件 运行tesseract命令,tesseract mjorc ...

  5. DDL DML DCL TCL之不同

    http://www.orafaq.com/faq/what_are_the_difference_between_ddl_dml_and_dcl_commands DDL Data Definiti ...

  6. git-分支使用方式

    需求场景:假如你看着教程完成了一个项目,但是感觉第一次代码掌握不牢,想要进行第二次代码练习--如果某某心里想我还有初始备份文件,我此时的心里独白是你的硬盘还够用吗o(╯□╰)o 1 创建一个新分支 - ...

  7. strut2-学习笔记(二)

     Struts2学习笔记(二) 1. 自定义结果视图的类型(结果视图类型的应用) CAPTCHA图像(随机验证码图像) 实现步骤: (1)编写一个类实现com.opensymphony.xwork ...

  8. ubuntu环境下lnmp环境搭建(3)之Php

    1.lnmp详细  http://www.discuz.net/thread-3513107-1-1.html 2. 到php目录 http://blog.aboutc.net/linux/65/co ...

  9. SqlServer和Oracle中一些常用的sql语句9 SQL优化

    --SQL查询优化 尽量避免使用or,not,distinct运算符,简化连接条件 /*Or运算符*/ use db_business go select * from 仓库 where 城市='北京 ...

  10. 使用HDFS客户端java api读取hadoop集群上的信息

    本文介绍使用hdfs java api的配置方法. 1.先解决依赖,pom <dependency> <groupId>org.apache.hadoop</groupI ...