AcWing 3711. 方格涂色(枚举)

题目:3711. 方格涂色

在这里插入图片描述
在这里插入图片描述
题解:对四个边,起到联系的是四个顶点,那么我们枚举这四个顶点的状态(0、1),也就是说有1<<4种情况,枚举每种情况,看看是否能让四条边满足要求即可

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef pair<int ,int> PII;
const int N=1e5+10;
const int mod=100000007;
int a[4];
int n,U,R,D,L;
bool check(){
    if(a[0]+a[1]<=U&&U<=a[0]+a[1]+n-2){
        if(a[1]+a[2]<=R&&R<=a[1]+a[2]+n-2){
            if(a[3]+a[2]<=D&&D<=a[3]+a[2]+n-2){
                if(a[0]+a[3]<=L&&L<=a[0]+a[3]+n-2){
                    return true;
                }
            }
        }
    }
    return false;
}
int main(){
    int T;
    cin>>T;
    while(T--){

        cin>>n>>U>>R>>D>>L;
        bool flag=0;
        for(int i=0;i<(1<<4);i++){
            memset(a,0,sizeof a);
            for(int j=0;j<4;j++){
                if(i>>j&1) a[j]++;
            }
            if(check()){
                flag=1;
            }
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值