CUIT ACM Personal Training 11.27(FM)B - IQ Test

B - IQ Test
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 Input

Input
####
.#..
####
....
Output
YES
Input
####
....
####
....
Output
NO

Hint

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.


题解:这个题其实就是找到一个2*2的方格,改变一个颜色(或者不改变),使得这格子里面的颜色相同,这里的‘#’和‘.’分别代表黑白。那么我们只要扫描整个图,然后建一个二维数组,读取‘#’时,就在那个坐标上填上1,‘.’就是0,。当我们从第一排第一个开始到第三排第三个结束,每次都是计算那个点与左边下边和左下角一共四个格子里面数字的和,如果不是2,那么说明,只要改变其中的一种颜色,就可以存在2*2的格子里面颜色相同的情况。

比如和为0,那么都为白色,正确。

比如和为1,那么就有一个黑色,三个白色,只要把那个黑色变成白色,就有四个白色了,正确;

比如和为3,那么就有一个白色,三个黑色,只要把那个白色变成黑色,就有四个黑色了,正确;

比如和为4,那么都为黑色,正确。

只有当和为2时,有两个白色和两个黑色,只改一次是没有办法正确的。


AC代码如下:

#include<bits/stdc++.h>
using namespace std;

int a[5][5];
int main()
{
    int sum=0,flag=0;
    char ch;
    for(int i=0;i<4;i++)
        for(int j=0;j<4;j++)
        {
            cin>>ch;
            if(ch == '#') a[i][j]=1;
            if(ch == '.') a[i][j]=0;
        }
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
        {
            sum=a[i][j]+a[i][j+1]+a[i+1][j]+a[i+1][j+1];
            if(sum!=2) flag=1;
        }
    if(flag == 1) printf("YES\n");
    else printf("NO\n");
}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值