码迷,mamicode.com
首页 > 其他好文 > 详细

(思维)B. Berland Crossword

时间:2021-03-05 13:15:01      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:open   bre   clu   long   ref   namespace   cpp   false   vector   

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;
}


(思维)B. Berland Crossword

标签:open   bre   clu   long   ref   namespace   cpp   false   vector   

原文地址:https://www.cnblogs.com/phr2000/p/14483125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!