HDU 5926 Basic Mr. Frog’s Game 瞎搞

Mr. Frog’s Game

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

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

2016CCPC东北地区大学生程序设计竞赛 - 重现赛

题目名字太暴力了....

做的时候辅助输出的没删掉 wa了15min 感觉智商被掏空....

题目本身比较水

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define INFLL   0x3f3f3f3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;
typedef pair<int, int> PII;
using namespace std;

int mp[35][35];
int flag = 0;
int n, m;

void dfs(int x, int y, int num) {
    if(flag) return ;
    if(x == 1 || x == n) {
        for(int i = 1; i <= m; i++) {
            if(i == y) continue;
            if(mp[x][i] == num) flag = 1;
        }

    }
    if(y == 1 || y == m) {
        for(int i = 1; i <= n; i++) {
            if(i == x) continue;
            if(mp[i][y] == num) flag = 1;
        }
    }
    if(mp[x + 1][y] == num || mp[x - 1][y] == num || mp[x][y + 1] == num || mp[x][y - 1] == num) flag = 1;
}

int main() {
    //FIN
    int T;
    int cnt = 1;
    scanf("%d", &T);
    while(T--) {
        scanf("%d%d", &n, &m);
        memset(mp, -1, sizeof(mp));
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                scanf("%d", &mp[i][j]);
            }
        }

        flag = 0;
        for(int i = 1; i<= n; i++) {
            for(int j = 1; j <= m; j++) {
                dfs(i, j, mp[i][j]);
            }
        }
        if(flag) printf("Case #%d: Yes\n", cnt++);
        else printf("Case #%d: No\n", cnt++);

    }
    return 0;
}

  

时间: 2024-10-14 06:19:52

HDU 5926 Basic Mr. Frog’s Game 瞎搞的相关文章

HDU 1022 Train Problem I 用栈瞎搞

题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种情况是:开进来立马有开出去.并用vis[]数组的0,1标记进出站情况. 具体看代码 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm&

HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 312    Accepted Submission(s): 219 Problem Description One day, you, a clever boy, feel bored in your math class, and then fall

HDU5926 Mr. Frog’s Game

1 /* 2 HDU5926 Mr. Frog's Game 3 http://acm.hdu.edu.cn/showproblem.php?pid=5926 4 杂题水题 5 * 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 using namespace std; 10 const int Nmax=35; 11 int t,n,m; 12 int mapp[Nmax][Nmax]; 13 int dx[]={0,1,-1,

HDU 5929 Basic Data Structure 模拟

Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack: ? PUSH x: p

HDU5924 Mr. Frog’s Problem

1 /* 2 HDU5924 Mr. Frog's Problem 3 http://acm.hdu.edu.cn/showproblem.php?pid=5924 4 数论 5 * 6 */ 7 #include <cstdio> 8 int main() 9 { 10 long long a,b; 11 int t; 12 scanf("%d",&t); 13 for(int k=1;k<=t;k++) 14 { 15 scanf("%lld%l

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来...每道题都错好多次...很考察细节.比如这道....WA了无数次.... 这题的思路自己真心想不到...这题是将进制后的数分别是1位,2位,3位和更多位的分开来计算. 当是1位的时候,显然只有3到6,此时只能是-1 当是2位的时候,可以转换成一元一次方程求解 当是3位的时候,可以转换成一元二次方程求解 当是4位的时候,此时最多也只有7000个数,7000^3接近1e12.所以剩下的直接枚举进制数来判断即可. 代码如下: #include <i

HDU 4923 Room and Moor(瞎搞题)

瞎搞题啊.找出1 1 0 0这种序列,然后存起来,这种情况下最好的选择是1的个数除以这段的总和.然后从前向后扫一遍,变扫边进行合并.每次合并,合并的是他的前驱.这样到最后从t-1找出的那条链就是最后满足条件的数的大小. Room and Moor Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 307    Accepted Su

HDU 4925 Apple Tree (瞎搞)

找到规律,各一个种一棵树,或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 197    Accepted Submission(s): 135 Problem Description I've bought an orchard and decide to plant some

HDU 5024 Wang Xifeng&#39;s Little Plot(暴力枚举+瞎搞)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. Thi