[codeforces1494B]Berland Crossword

description:
Color some of the cells of the \(n*n\) square's edge black, check if there exists an solution of given black cells of each edge.
solution:
consider the \(4 corners\), just \(O(16)\) (bruteforce).
code:

#include<cstdio>
int black[4];
int n;
int x[4];
bool Enum() {
	bool flg = 0;
	for (int i = 0; i < 16; ++i) {
		for (int j = 0; j < 4; ++j)
			x[j] = i >> j & 1;
		bool f = 1;
		for (int j = 0; j < 4; ++j) {
			if (black[j]> n - 2 + x[j] + x[(j + 1) % 4] || black[j] < x[j] + x[(j + 1) % 4])
				f = 0;
		}
		flg = f;
		if (flg == 1)break;
	}
	return flg;

}
int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 0; i < 4; ++i)
			scanf("%d", black + i);
		Enum() ? puts("YES") : puts("NO");
	}
}
posted @ 2021-03-05 21:29  _dwt  阅读(52)  评论(0)    收藏  举报