F. New Year's Puzzle

F. New Year's Puzzle

/*
 短代码模拟就是我的人生理想
 很妙的奇偶性:如果两个黑块的奇偶性不同
 比如正好一上一下,这两个可以当成一组,也就意味着前面必然可以填满

*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout<<#x<<':'<<x<<endl;
#define x first
#define y second
void Ios(){
ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
}
map<int,int>mp;

int main(){
    int T,x,y;
    cin>>T;
    while(T--){
        mp.clear();
        bool flag=true;
        int n,m;cin>>n>>m;
        vector<int>vc1,vc2,vc3;
        for(int i=1;i<=m;i++){
            cin>>x>>y;
            mp[y]|=1<<(x-1);
        
        }
        int haslast=0,lastcolor=0;
        mp[n+1]=3;
        for(auto q:mp){
            //debug(q.x);debug(q.y);cout<<endl;
            if(q.y==3&&haslast){
                flag=false;
                //cout<<"#1"<<endl;
                break;
            }
            else if(haslast==1){
                if(lastcolor==(q.x+q.y)%2){
                    flag=false;
                    //cout<<"#2"<<endl;
                    break;
                }
                else {
                    haslast=0;
                    //cout<<"#3"<<endl;
                }
            }
            else if(q.y!=3){
                lastcolor=(q.x+q.y)%2;
                haslast=1;
                //cout<<"#4"<<endl;
            }
            
        }
    if(flag) cout<<"YES"<<endl;
    else if(!flag) cout<<"NO"<<endl;

    }
}
原文地址:https://www.cnblogs.com/zx0710/p/14470855.html