zoukankan      html  css  js  c++  java
  • Mr. Frog’s Game

    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. 

    InputThe first line contains only one integer T (T≤500T≤500), which indicates the number of test cases. 

    For each test case, the first line contains two integers n and m (1≤n,m≤301≤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). 
    OutputFor 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.
    
    
    //只需判断外围每行或每列有没有相等的,内围上下左右有没有与它相等的
    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <algorithm>
    #include <stdlib.h>
    using namespace std;
    int main()
    {
        long long int T,i,j,o;
        scanf("%lld",&T);
        for(o=1;o<=T;o++)
        {
            long long int n,m,s=0,a[100][100];
            scanf("%lld%lld",&n,&m);
            for(i=1;i<=n;i++)
                for(j=1;j<=m;j++)
                    scanf("%lld",&a[i][j]);
            for(j=1;j<m;j++)
                for(i=j+1;i<=m;i++)
                    if(a[1][j]==a[1][i])
                        s++;
            for(j=1;j<m;j++)
                for(i=j+1;i<=m;i++)
                    if(a[n][j]==a[n][i])
                        s++;
            for(j=1;j<n;j++)
                for(i=j+1;i<=n;i++)
                    if(a[j][1]==a[i][1])
                        s++;
            for(j=1;j<n;j++)
                for(i=j+1;i<=n;i++)
                    if(a[j][m]==a[i][m])
                        s++;
            if(s>0)
                printf("Case #%d: Yes
    ",o);
            else
            {
                for(i=1;i<n;i++)
                    for(j=1;j<m;j++)
                        if(a[i][j]==a[i][j+1]||a[i][j]==a[i+1][j])
                            s++;
                if(s>0)
                    printf("Case #%d: Yes
    ",o);
                else
                    printf("Case #%d: No
    ",o);
            }
        }
        return 0;
    }
  • 相关阅读:
    Vue-Router路由 Vue-CLI脚手架和模块化开发 之 路由常用配置与路由嵌套
    (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087
    最大连续子序列 -- hdu -- 1231
    (KMP灵活运用 利用Next数组 )Theme Section -- hdu -- 4763
    (KMP 水)Wow! Such Doge! -- hdu -- 4847
    (回文串 Manacher )Girls' research -- hdu -- 3294
    (回文串 Manacher)吉哥系列故事——完美队形II -- hdu -- 4513
    (回文串 )Best Reward -- hdu -- 3613
    Center Alignment
    Chat Server's Outgoing Traffic
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702801.html
Copyright © 2011-2022 走看看