A. IQ Test

來源:互聯網
上載者:User
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.

解題說明:此題的意思很明確,最多改變4*4地區內的一個值找出一個2*2地區,該地區內的值完全相同。雖然輸入為字串,但比較起來還是麻煩,可以轉換為數字矩陣來做,“#”的位置標記為1,“.” 的位置標記為0,這樣判斷時只需要對一個2*2的矩形值求和,判斷值是否等於2,如果等於2,證明有兩黑兩白,無法通過僅改變一塊實現題目要求,其它數字滿足題意。

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main(){int a[4][4],i,j,k,s,flag;char c;flag=0;for(i=0;i<4;i++){for(j=0;j<4;j++){cin>>c;if(c=='#'){a[i][j]=1;}else{a[i][j]=0;}}}for(i=0;i<3;i++){for(j=0;j<3;j++){s=0;for(k=i;k<=i+1;k++){s=s+a[k][j]+a[k][j+1];}if(s!=2){cout<<"YES"<<endl;flag=1;goto ABC;}}}ABC:if(flag==0){cout<<"NO"<<endl;}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.