zoukankan      html  css  js  c++  java
  • [NOI2014]起床困难综合症

    炒鸡大水题!

    从高到低枚举每一位能不能取1,然后分别算出该位取0和取1的答案再比对。

    // It is made by XZZ
    #include<cstdio>
    #include<algorithm>
    #define il inline
    #define rg register
    #define vd void
    #define sta static
    typedef long long ll;
    il int gi(){
        rg int x=0,f=1;rg char ch=getchar();
        while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
        while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
        return x*f;
    }
    const int maxn=1e5+1;
    int a[maxn],op[maxn];
    char opt[10];
    il int calc(int x,int y,int o){
        if(o==1)return x&y;
        else if(o==2)return x|y;
        else return x^y;
    }
    int main(){
        int n=gi(),m=gi();
        for(rg int i=1;i<=n;++i){
            scanf("%s",opt);a[i]=gi();
            if(opt[0]=='A')op[i]=1;
            else if(opt[0]=='O')op[i]=2;
            else op[i]=3;
        }
        int A0=0,A1=(1<<30)-1;
        for(rg int j=1;j<=n;++j)A0=calc(A0,a[j],op[j]);
        for(rg int j=1;j<=n;++j)A1=calc(A1,a[j],op[j]);
        int ans=0,atk=0;
        bool x,a0,a1;
        for(rg int i=29;~i;--i){
            a0=A0&(1<<i);
            a1=A1&(1<<i);
            if(atk+(1<<i)>m)a1=0;
            if(a1==1&&a0==0)atk+=1<<i,ans+=1<<i;
            else if(a0==1)ans+=1<<i;
        }
        printf("%d
    ",ans);
        return 0;
    }
    
  • 相关阅读:
    Hibernate实现limit查询报错 :unexpected token: limit near line 1, column 33 [from pojo.Product p order by id limit ?,? ]
    slot_filling
    Perplexity(困惑度)
    图网络
    textrank
    copynet
    PGN
    beam-search的改进
    项目实战:如何构建知识图谱
    实体关系三元组抽取
  • 原文地址:https://www.cnblogs.com/xzz_233/p/8473229.html
Copyright © 2011-2022 走看看