zoukankan      html  css  js  c++  java
  • CF1214题解

    D

    因为可以用贡献2把起点终点堵掉,所以答案为0/1/2

    0/2简单

    1:方格可以理解为分层图,考虑每个能到达终点,起点能到达其的点,标记一下,对角线如果仅存在1则为必经之路

    E

    (d_ile n),我们先把(2,4,..,2n)提出来单独拉一条链,然后乱搞即可

    F

    咕咕

    G

    似乎是比较套路的题%%%

    单独考虑两行A,B是否有解

    无解当且仅当A是B的子集或B是A的子集

    (C=A&B),则(A^C)(1)的位置则,(A)(1),(B)(0)
    (B)同理

    全局无解当且仅当按1个数排序后,相邻的全为包含关系,故我们可以排序后仅根据相邻的判断答案即可

    用bitset优化

    #include<bits/stdc++.h>
    typedef int LL;
    #define mp std::make_pair
    inline LL Read(){
        LL x(0),f(1); char c=getchar();
        while(c<'0' || c>'9'){
            if(c=='-') f=-1; c=getchar();
        }
        while(c>='0' && c<='9'){
            x=(x<<3)+(x<<1)+c-'0'; c=getchar();
        }return x*f;
    }
    const LL maxn=2e3+9;
    LL n,m,q;
    std::bitset<maxn> A[maxn],fac[maxn],C,b1,b2;
    struct node{
    	LL fir,sec;
    	bool operator < (const node &x)const{
    		return sec<x.sec || (sec==x.sec && fir<x.fir);//set的比较大小 如出现相对大小则会删去一个 
    	}
    };
    std::set<node > S;
    std::set<std::pair<LL,LL> > ans;
    std::set<node >::iterator it1,it2,it3;
    std::set<std::pair<LL,LL> >::iterator It1;
    inline bool cmp(LL x,LL y){
    	C=A[x]&A[y];
    	if(C!=A[x] && C!=A[y]) return true; return false;
    }
    inline void Modify(LL x,LL cnt,LL ty){
    	it1=S.find((node){x,cnt}); it2=it1; it2++;
    	if(it1!=S.begin()){
    		it3=it1; it3--;
    		if(ty==-1) ans.erase(mp(it3->fir,it1->fir));
    		else if(cmp(it3->fir,it1->fir)) ans.insert(mp(it3->fir,it1->fir));
    	}
    	if(it2!=S.end()){
    		if(ty==-1) ans.erase(mp(it1->fir,it2->fir));
    		else if(cmp(it1->fir,it2->fir)) ans.insert(mp(it1->fir,it2->fir));
    	}
    	if(it1!=S.begin() && it2!=S.end()){
    		--it1;
    		if(ty==1) ans.erase(mp(it1->fir,it2->fir));
    		else if(cmp(it1->fir,it2->fir)) ans.insert(mp(it1->fir,it2->fir));
    	}
    }
    int main(){
    	n=Read(); m=Read(); q=Read();
    	for(LL i=1;i<=n;++i) S.insert((node){i,0});
    	for(LL i=1;i<=m;++i){
    		fac[i]=fac[i-1]; fac[i][i]=1;
    	}
    	while(q--){
    		LL x(Read()),l(Read()),r(Read());
    		LL cnt(A[x].count());
    		Modify(x,cnt,-1);
    		S.erase((node){x,cnt});
    		A[x]^=((fac[r]>>l)<<l);
    		cnt=A[x].count();
    		S.insert((node){x,cnt});
    		Modify(x,cnt,1);
    		if(ans.empty()) puts("-1");
    		else{
    			It1=ans.begin();
    			LL x(It1->first),y(It1->second);
    			C=A[x]&A[y];
    			b1=A[x]^C; b2=A[y]^C;
    			LL y1(b1._Find_first()),y3(b2._Find_first());
    			if(x>y) std::swap(x,y);
    			if(y1>y3) std::swap(y1,y3);
    			printf("%d %d %d %d
    ",x,y1,y,y3);
    		}
    	}
    	return 0;
    }
    

    H

    神仙题

    假设一条链,则按序染色即可

    设有三个分叉,链长为(a,b,c),设(age bge c),则(b+cge k)
    证明:(a)(b)(c)一个段的位置,(b)(c)比可以让其构成一个段,由于重复比无解

    注意必须(kge 2),因为(k=2)时不可能一条链由两个分叉组成

    寻找解:找到直径,由于其他的点到直径的一端点一定是最远的,故由两端点找次短及三次短判断即可
    构造解:直径端点为根遍历,按深度染色

  • 相关阅读:
    use other gpio pins as i2c
    systemd详解详解
    Python ctype sizeof incorrect!
    libvirt 安装篇
    Django Restful Framework (二): ModelSerializer
    Django Restful Framework (一): Serializer
    libvirt 网络手册(二):桥接网络
    KVM 虚拟机联网方式:NAT 和 Bridge
    libvirt 网络手册(一)
    CentOS 7 环境配置
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/11569650.html
Copyright © 2011-2022 走看看