A. IQ Test
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other)
Total Submission(s) : 32 Accepted Submission(s) : 11
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.
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.
Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.
#### .#.. #### .... #### .... #### ....
YES NO这题只要判断4个方位就行了AC代码:#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm> #include<queue> #include<stack> #include<set> #include<iomanip> #include<string> #include<cstring> const int MAX=5; char map[MAX][MAX]; using namespace std; int main() { int i,j,b,w,p; while(cin>>map[0]) { getchar(); for(i=1;i<=3;i++) cin>>map[i]; p=0; for(i=0;i<3;i++) { for(j=0;j<3;j++) { b=0; w=0; if(map[i][j]=='#') w+=1; else b+=1; if(map[i+1][j]=='#') w+=1; else b+=1; if(map[i][j+1]=='#') w+=1; else b+=1; if(map[i+1][j+1]=='#') w+=1; else b+=1; if(w>=3||b>=3) { p=1; break; } } if(p) break; } if(p) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }