(思维)B. Berland Crossword
\(直接去枚举四个角落,注意枚举的方法,本题如何写的简洁很关键.\)
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define VIT vector<int>
#define x first
#define y second
#define inf 0x3f3f3f3f
int a[4];
int n;
int check(int state) {
int b[4];
for (int i = 0; i < 4; ++i) b[i] = state >> i & 1;
for (int i = 0; i < 4; ++i) {
int x = b[i], y = i + 1 == 4 ? b[0] : b[i + 1];
if (x + y > a[i]) return 0;
if (x + y + n - 2 < a[i]) return 0;
}
return 1;
}
int main() {
//freopen("in.txt", "r", stdin);
IO;
int _;
cin >> _;
while (_--) {
int f = 0;
cin >> n;
for (int i = 0; i < 4; ++i) cin >> a[i];
for (int i = 0; i < 16; ++i) {
f = check(i);
if (f) break;
}
puts(f ? "YES" : "NO");
}
return 0;
}