3711. 方格涂色

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种方案,用二进制表示是否需要涂色,然后对每一条边的长度进行判断是否符合要求,只要有一种状态符合要求就可以。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值