Codeforces-287a C IQ Test

来源:互联网 发布:乐高 机器人 编程 编辑:程序博客网 时间:2024/05/16 06:41
A. IQ Test
time limit per test
2 seconds
memory limit per test
256 megabytes

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 repaintat most one cell the other color so that the picture has a2 × 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 a2 × 2 square, consisting of cells of the same color.

Input

Four lines contain four characters each: the j-th character of thei-th line equals "." if the cell in thei-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 required2 × 2 square is on the intersection of the1-st and 2-nd row with the1-st and 2-nd column.

————————————————————扎实的分割线————————————————————

思路:水题,纯模拟。枚举2×2的矩形。一旦一个小矩形内出现3个或3个以上# or . 称为有解。

代码如下:

#include <stdio.h>#include <string.h>int main(){char a[5][5];int i, j, flag = 0;for(i = 0; i < 4; i++)        scanf("%s", a[i]);for(i = 0; i < 3; i++){//仅需要三次,想一想为什么        for(j = 0; j < 3; j++){            int x = 0, y = 0;            if(a[i][j] == '#')     x++;  else y++;            if(a[i][j+1] == '#')   x++;  else y++;            if(a[i+1][j] == '#')   x++;  else y++;            if(a[i+1][j+1] == '#') x++;  else y++;            if(x >= 3||y >= 3){                flag = 1;                break;            }        }        if(flag)  break;}printf("%s\n", flag ? "YES" : "NO");return 0;}


0 0
原创粉丝点击