AcWing 3711. 方格涂色--Java
原题链接
中等
作者:
卡曼橘
,
2021-06-23 11:49:57
,
所有人可见
,
阅读 156
import java.util.Scanner;
public class Main
{
static int n , u, r, d, l;
public static void main(String[] agrs)
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T > 0)
{
n = sc.nextInt();
u = sc.nextInt();r = sc.nextInt();
d = sc.nextInt();l = sc.nextInt();
boolean f = false;
for(int i = 0; i < 16; i ++)
{
if(check(i)) f = true;
}
if(f) System.out.println("YES");
else System.out.println("NO");
T --;
}
}
static boolean check(int i)
{
int[] a = new int[4];
for(int j = 0; j < 4; j ++)
{
// if( (i & 1 << j) != 0 ) a[j] = 1;
// else a[j] = 0;
a[j] = i >> j & 1 ;
}
if( !(a[0] + a[1] <=u && u <= a[0] + a[1] + n-2) ) return false;
if( !(a[1] + a[2] <=r && r <= a[1] + a[2] + n-2) ) return false;
if( !(a[2] + a[3] <=d && d <= a[2] + a[3] + n-2) ) return false;
if( !(a[3] + a[0] <=l && l <= a[3] + a[0] + n-2) ) return false;
return true;
}
}