zoukankan      html  css  js  c++  java
  • 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): 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 (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 5928 5927 
    /*
    这个题可以搜索,但是30*30完全可以暴力
    */
    #include<bits/stdc++.h>
    using namespace std;
    int pa[32][32];
    int main()
    {
        //freopen("C:\Users\acer\Desktop\in.txt","r",stdin);
        int T,nl = 0,N,M,i,j,pl;
        scanf("%d",&T);
        while(T--)
        {
            pl = 0;
            scanf("%d%d",&N,&M);
            for(i = 1 ; i <= N; i++)
                for(j = 1 ; j <= M; j++)
                    scanf("%d",&pa[i][j]);
            for(i = 1 ; i < M ; i++)///判断边上是不是有相同的
            {
               for(j = i + 1 ; j <= M ; j++)
                   if((pa[1][i] == pa[1][j]) || (pa[N][i] == pa[N][j]))
                       pl = 1;
                if(pl) break;
            }
            if(!pl)
            {
                for(i = 1 ; i < N ; i++)///判断是不是有相连的有相同的
                {
                    for(j = i + 1 ; j <= N ; j++)
                        if((pa[i][1] == pa[j][1]) || (pa[i][M] == pa[j][M]))
                            pl = 1;
                    if(pl) break;
                }
                if(!pl)
                {
                    for(i = 1 ; i <= N ; i++)///判断是不是有相连的有相同的
                    {
                        for(j = 1 ; j <= M ; j++)
                        {
                            if(i!= N && pa[i][j] == pa[i + 1][j]) pl = 1;
                            if(j!= M && pa[i][j] == pa[i][j + 1]) pl = 1;
                        }
                        if(pl) break;
                    }
                }
            }
            if(pl)
                printf("Case #%d: Yes
    ",++nl);
            else
                printf("Case #%d: No
    ",++nl);
        }
        return 0;
    }
  • 相关阅读:
    shell进阶——expect免交互工具的使用
    SSH非交互式密码授权远程执行脚本---转载
    github新项目上传操作(下面的例子以centos7-redis-shell项目为实例)
    camstar跨平台开发
    C/C++语言中的int所能表示的最大值最小值
    剑指offer 15:二进制中1的个数
    剑指offer33:二叉搜索树的后序遍历序列
    剑指offer31:栈的压入弹出序列
    剑指offer:包含min函数的栈
    剑指offer50拓展:字符流中第一个不重复的字符
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/6005329.html
Copyright © 2011-2022 走看看