3711. 方格涂色
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;
const int N = 120;
int t;
int n;
int u, r, d, l;
bool check(int state){
int a = state >> 0 & 1, b = state >> 1 & 1;
int x = state >> 2 & 1, y = state >> 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() {
cin >> t;
while (t--) {
scanf("%d%d%d%d%d", &n, &u, &r, &d, &l);
bool flag = false;
for (int i = 0; i < 16;++i)
if(check(i)){
flag = true;
break;
}
if(flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
题解:主要是要判断四个角到底需不需要涂色,因为这里只有四个格子,所以用枚举共有16种方案。用数字来状态压缩这16种方案,用二进制表示是否需要涂色,然后对每一条边的长度进行判断是否符合要求,只要有一种状态符合要求就可以。