题目:3711. 方格涂色
题解:对四个边,起到联系的是四个顶点,那么我们枚举这四个顶点的状态(0、1),也就是说有1<<4种情况,枚举每种情况,看看是否能让四条边满足要求即可
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int> PII;
const int N=1e5+10;
const int mod=100000007;
int a[4];
int n,U,R,D,L;
bool check(){
if(a[0]+a[1]<=U&&U<=a[0]+a[1]+n-2){
if(a[1]+a[2]<=R&&R<=a[1]+a[2]+n-2){
if(a[3]+a[2]<=D&&D<=a[3]+a[2]+n-2){
if(a[0]+a[3]<=L&&L<=a[0]+a[3]+n-2){
return true;
}
}
}
}
return false;
}
int main(){
int T;
cin>>T;
while(T--){
cin>>n>>U>>R>>D>>L;
bool flag=0;
for(int i=0;i<(1<<4);i++){
memset(a,0,sizeof a);
for(int j=0;j<4;j++){
if(i>>j&1) a[j]++;
}
if(check()){
flag=1;
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}