题目传送门
思路:
容易发现除了四个角以外,每条边上的格子不会相互影响,所以关键是四个角的状态。穷举所有四个角的情况,然后逐一判断。
代码如下:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
const int INF=0x3f3f3f3f;
int T,n,u,r,d,l;
bool judge(int x,int y,int z,int w){
if(x+y+n-2<u||x+y>u){
return 0;
}
if(y+z+n-2<r||y+z>r){
return 0;
}
if(z+w+n-2<d||z+w>d){
return 0;
}
if(x+w+n-2<l||x+w>l){
return 0;
}
return 1;
}
bool solve(){
for(int x=0;x<=1;x++){
for(int y=0;y<=1;y++){
for(int z=0;z<=1;z++){
for(int w=0;w<=1;w++){
if(judge(x,y,z,w)){
return 1;
}
}
}
}
}
return 0;
}
signed main(){
cin>>T;
while(T--){
cin>>n>>u>>r>>d>>l;
if(solve()){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}
完结撒花~