题目
题解思路
首先想到了肯定是4个顶点,对四条边的影响,我们可以对每条边分别进行特判,当他大于n-2的时候就必须涂顶点,为了减少影响,我们肯定让他涂在要涂的地方多的位置,最后在判断值是否合法就可以,不过模拟的比较麻烦。
闫总用的是二进制枚举来枚举枚举4个顶点涂和不涂的情况,对每个情况,进行判断,只要有一个满足即可。
AC代码
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int n,u,r,d,l;
bool check(int p)
{
int a = p >> 0 & 1, b = p >> 1 & 1;
int x = p >> 2 & 1, y = p >> 3 & 1;
if (!(a + b <= u && u <= a + b + n - 2)) return false;
if (!(x + y <= d && d <= x + y + n - 2)) return false;
if (!(a + x <= l && l <= a + x + n - 2)) return false;
if (!(b + y <= r && r <= b + y + n - 2)) return false;
return true;
}
int main ()
{
int t;
cin>>t;
while(t--)
{
int book = 0 ;
cin>>n>>u>>r>>d>>l;
for (int i = 1 ; i <= 16 ; i++ )
{
if (check(i))
{
book = 1;
break;
}
}
if ( book )
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}