CodeForces

题目链接

题目大意

  给你一个(n imes n)的正方形网格,然后问上下两行和左右两列能否放置u,d,l,r个格子。

解题思路

  直接暴力枚举四个角的放置情况,然后判断所给的数字是否在可行的范围就行了。

代码

const int maxn = 1e5+10;
const int maxm = 2e5+10;
int main() {	
	int __; cin >> __;
	int n, u, r, d, l;
	while(__--) {
		cin >> n >> u >> r >> d >> l;
		int a[5];
		bool ok = 0;
		for (int i = 0; i<1<<4; ++i) {
			for (int j = 0; j<4; ++j) {
				if (i>>j&1) a[j] = 1;
				else a[j] = 0;
			}
			int u2 = a[0]+a[1];
			int r2 = a[1]+a[2];
			int d2 = a[2]+a[3];
			int l2 = a[3]+a[0];
			ok |= (u>=u2 && u<=u2+n-2 && r>=r2 && r<=r2+n-2 && d>=d2 && d<=d2+n-2 && l>=l2 && l<=l2+n-2);
 		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
 	}
	return 0;	
} 
原文地址:https://www.cnblogs.com/shuitiangong/p/14476477.html