• bzoj3668 [Noi2014]起床困难综合症


    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3668

    【题解】

    我们枚举每位选啥即可。如果选0就能使最后变成1,显然选0,如果选1还不能使最后变成1,那么选0,否则选1.

    日哦。。2^31刚好爆int

    # include <stdio.h>
    # include <string.h>
    # include <algorithm>
    // # include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    const int M = 5e5 + 10;
    const int mod = 1e9+7;
    
    # define RG register
    # define ST static
    
    int n, m;
    struct pa {
        int op, x;
        pa() {}
        pa(int op, int x) : op(op), x(x) {}
    } p[M];
    char str[5];
    
    int main() {
        scanf("%d%d", &n, &m);
        for (int i=1, x; i<=n; ++i) {
            scanf("%s%d", str, &x);
            if(!strcmp(str, "AND")) p[i] = pa(1, x);
            if(!strcmp(str, "OR")) p[i] = pa(2, x);
            if(!strcmp(str, "XOR")) p[i] = pa(3, x);
        }
        int cur = 0, ans = 0;
        # define g ((p[j].x>>i)&1)
        for (int i=30; ~i; --i) {
            int a = 0;
            for (int j=1; j<=n; ++j) {
                if(p[j].op==1) a = a & g;
                if(p[j].op==2) a = a | g;
                if(p[j].op==3) a = a ^ g;
            }
            if(a) continue;
            a = 1;
            for (int j=1; j<=n; ++j) {
                if(p[j].op==1) a = a & g;
                if(p[j].op==2) a = a | g;
                if(p[j].op==3) a = a ^ g;
            }
            if(a && (ans+(1<<i)) <= m) ans = ans + (1<<i);
        }
        for (int j=1; j<=n; ++j) {
            if(p[j].op==1) ans = ans & p[j].x;
            if(p[j].op==2) ans = ans | p[j].x;
            if(p[j].op==3) ans = ans ^ p[j].x;
        }
        # undef g
        printf("%d
    ", ans);        
        return 0;
    }
    View Code
  • 相关阅读:
    Python爬虫3大解析库使用导航
    pyquery解析库的介绍和使用
    BeautifulSoup解析库的介绍和使用
    Xpath解析库的使用
    python爬虫之正则表达式(用在其他地方也可)
    requests的基本使用
    Linux下防范小型cc攻击
    图片素材资源
    postman安装
    edraw快捷键
  • 原文地址:https://www.cnblogs.com/galaxies/p/bzoj3668.html
Copyright © 2020-2023  润新知