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)
Total Submission(s): 277    Accepted Submission(s): 192


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 ( T500), which indicates the number of test cases.

For each test case, the first line contains two integers n and m (1n,m30).

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  5929  5928 
 

 

Statistic |  Submit |  Discuss |  Note

 

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5926

题目大意:

  N*M(N,M<=30)的格子,求连连看第一步是否能连。

题目思路:

  【模拟】

  +1s 直接枚举相邻的,最外层的能否跨接即可。

 

 1 //
 2 //by coolxxx
 3 //#include<bits/stdc++.h>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<string>
 7 #include<iomanip>
 8 #include<map>
 9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #pragma comment(linker,"/STACK:1024000000,1024000000")
21 #define min(a,b) ((a)<(b)?(a):(b))
22 #define max(a,b) ((a)>(b)?(a):(b))
23 #define abs(a) ((a)>0?(a):(-(a)))
24 #define lowbit(a) (a&(-a))
25 #define sqr(a) ((a)*(a))
26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
27 #define mem(a,b) memset(a,b,sizeof(a))
28 #define eps (1e-10)
29 #define J 10000
30 #define mod 1000000007
31 #define MAX 0x7f7f7f7f
32 #define PI 3.14159265358979323
33 #define N 34
34 using namespace std;
35 typedef long long LL;
36 double anss;
37 LL aans;
38 int cas,cass;
39 int n,m,lll,ans;
40 int a[N][N];
41 int dx[]={-1,1,0,0};
42 int dy[]={0,0,-1,1};
43 bool judge()
44 {
45     int i,j,k;
46     for(i=2;i<n;i++)
47         for(j=2;j<m;j++)
48             for(k=0;k<4;k++)
49                 if(a[i][j]==a[i+dx[k]][j+dy[k]])return 1;
50     for(i=1;i<n;i++)
51         for(j=i+1;j<=n;j++)
52             if(a[1][i]==a[1][j] || a[n][i]==a[n][j])return 1;
53     for(i=1;i<m;i++)
54         for(j=i+1;j<=m;j++)
55             if(a[i][1]==a[j][1] || a[i][m]==a[j][m])return 1;
56     return 0;
57 }
58 int main()
59 {
60     #ifndef ONLINE_JUDGEW
61 //    freopen("1.txt","r",stdin);
62 //    freopen("2.txt","w",stdout);
63     #endif
64     int i,j,k;
65     int x,y,z;
66 //    init();
67 //    for(scanf("%d",&cass);cass;cass--)
68     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
69 //    while(~scanf("%s",s))
70 //    while(~scanf("%d%d",&n,&m))
71     {
72         printf("Case #%d: ",cass);
73         scanf("%d%d",&n,&m);
74         for(i=1;i<=n;i++)
75             for(j=1;j<=m;j++)
76                 scanf("%d",&a[i][j]);
77         if(judge())puts("Yes");
78         else puts("No");
79     }
80     return 0;
81 }
82 /*
83 //
84 
85 //
86 */
View Code

 

转载于:https://www.cnblogs.com/Coolxxx/p/5983754.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值