B. Berland Crossword
思路
这道题的关键在于四个角的状态,我们只需将四个角的状态全部模拟一遍测试是否由成立的情况就可。
当n==1的时候需要特判。
#include<iostream>
#include<cstring>
using namespace std;
int n;
int check(int x,int s)
{
if((x-s)>=0&&(x-s)<=(n-2)) return 1;
else return 0;
}
int main()
{
int t;
cin>>t;
while(t--) {
cin >> n;
if(n==1)
{
int u, r, d, l;
cin >> u >> r >> d >> l;
int sum=u+r+d+l;
if(sum==0||sum==4)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
} else
{
int u, r, d, l;
cin >> u >> r >> d >> l;
int t1,t2,t3,t4;
bool flag=false;
for(t1=0;t1<=1;t1++)
for(t2=0;t2<=1;t2++)
for(t3=0;t3<=1;t3++)
for(t4=0;t4<=1;t4++)
if(check(u,t1+t2)&&check(r,t2+t3)&&check(d,t3+t4)&&check(l,t4+t1)) flag=true;
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
}