Meaning of the questions simulation questions ---- super flood problem
Thoughts: This title is a thinking problem, a two-dimensional array and only two lines, and can be exchanged between the number and the number of observed cases find the law
Ideas: with a, b, c are stored array is the number of remainder 0,1,2
For two adjacent numbers can not be an integer 3, it is equivalent to the remainder remainder adjacent two numbers can not both be 0 and two numbers can not be adjacent to a 1 and a 2
1 | 0 | 0 | 2 | 2 | 2 | ||||
1 | 1 | 0 | 0 | 2 | 2 |
We simulate what a table:
0 and 0 will be similar to the positional relationship between the diagonal
1 and 2 to be spaced apart 0
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { int n,x; int a=0,b=0,c=0; scanf("%d",&n); for(int i=0;i<2*n;i++) { scanf("%d",&x); if(x%3==0) a++; if(x%3==1) b++; if(x%3==2) c++; } if(a>n) printf("NO\n"); else{ if(a<=1) { if(b!=0&&c!=0) printf("NO\n"); else printf("YES\n"); } else if(a==2) { IF (B% 2 == . 1 && C% 2 == . 1 ) // B, C 0 is also considered the printf ( " YES \ n- " ); the else the printf ( " NO \ n- " ); } else { printf("YES\n"); } } } }