• Codeforces Round #176 (Div. 2) A. IQ Test(简单搜索)


    A. IQ Test
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In the city of Ultima Thule job applicants are often offered an IQ test.

    The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed.

    Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.

    Input

    Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.

    Output

    Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.

    Sample test(s)
    input
    ####
    .#..
    ####
    ....
    output
    YES
    input
    ####
    ....
    ####
    ....
    output
    NO
    Note

    In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.

     1 #include <iostream>
     2 #include <fstream>
     3 #include <string>
     4 #include <set>
     5 //#include <map>
     6 #include <vector>
     7 #include <stack>
     8 #include <queue>
     9 #include <cmath>
    10 #include <cstdio>
    11 #include <cstring>
    12 #include <algorithm>
    13 #include <utility>
    14 using namespace std;
    15 #define ll long long
    16 #define cti const int
    17 #define ctll const long long
    18 #define dg(i) cout << '*' << i << endl;
    19 
    20 char map[5][5];
    21 const int move[4][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
    22 
    23 bool Check(int i, int j)
    24 {
    25     int w = 0, b = 0;
    26     for(int k = 0; k < 4; k++)
    27     {
    28         if(map[i + move[k][0]][j + move[k][1]] == '#') b++;
    29         else w++;
    30     }
    31     if(w == 1 || b == 1 || w == 0 || b == 0) return true;
    32     return false;
    33 }
    34 
    35 int main()
    36 {
    37     while(scanf("%s", map[0]) != EOF)
    38     {
    39         int ok = false;
    40         for(int i = 1; i < 4; i++)
    41             scanf("%s", map[i]);
    42         for(int i = 0; i < 3 && !ok; i++)
    43         {
    44             for(int j = 0; j < 3 && !ok; j++)
    45                 ok = Check(i, j);
    46         }
    47         if(ok) puts("YES");
    48         else puts("NO");
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    恢复更新
    Sun与Google结为战略合作伙伴, 可能联合Sun推出Web Office
    Outlook数据文件备份和按年存档的办法
    新装的几个软件试用体会(WPS 2005,Opera,QQ 2005 Beta3)
    关于VBA和Excel,GIS软件
    人格测试
    Taking a serious look at grids
    iPod、iMac 5、iTunes 6
    如此“自助”
    UCGIS优先研究领域介绍
  • 原文地址:https://www.cnblogs.com/cszlg/p/2990643.html
Copyright © 2020-2023  润新知