Codeforces 176 A

 

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.

#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

char s[5][5];

bool Fit(int x,int y)
{
    int w=0,b=0;
    for(int i=0;i<2;i++)
      for(int j=0;j<2;j++)
        if('.'==s[x+i][y+j])w++;
        else b++;
    //cout<<x<<" "<<y<<" "<<w<<" "<<b<<endl;
    return w!=b;
}

int main()
{
    
    for(int i=0;i<4;i++)
      cin>>s[i];
    int flag=0;
    for(int i=0;i<3;i++)
    {
        if(flag)break;
        for(int j=0;j<3;j++)
          if(Fit(i,j))
          {
              flag=1;
              break;
          }
    }
    if(flag)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

本文链接:Codeforces 176 A

转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:Rexdf,谢谢!^^


此条目发表在ACM分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。

*

:zsmilebig: :zsadbig: :zwiredbig: :zgreenhappy: more »

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据