zoukankan      html  css  js  c++  java
  • hdu 4768 异或运算

    http://acm.hdu.edu.cn/showproblem.php?pid=4768

    貌似非常多人是用的二分

    可是更好的做法貌似还是异或

    对于第k个人。假设他接到偶数个传单。那么异或的结果还是0

    就是说op记录全部收到传单的人次的总的异或值。那么由于仅仅有一个是收到奇数次。所以异或值就是他的编号,至于收到几次,在O(n)能够计算

    //#pragma comment(linker, "/STACK:102400000,102400000")
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <map>
    #include <set>
    #include <queue>
    using namespace std;
    
    #define ls(rt) rt*2
    #define rs(rt) rt*2+1
    #define ll long long
    #define ull unsigned long long
    #define rep(i,s,e) for(int i=s;i<e;i++)
    #define repe(i,s,e) for(int i=s;i<=e;i++)
    #define CL(a,b) memset(a,b,sizeof(a))
    #define IN(s) freopen(s,"r",stdin)
    #define OUT(s) freopen(s,"w",stdout)
    const ll ll_INF = ((ull)(-1))>>1;
    const double EPS = 1e-8;
    const double pi = acos(-1.0);
    const int INF = 100000000;
    const int MAXN = 20010  +20;
    
    int a[MAXN],b[MAXN],c[MAXN],n;
    
    int main()
    {
        while(~scanf("%d",&n)){
            int op=0,cnt=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d%d%d",&a[i],&b[i],&c[i]);
                for(int j=a[i];j<=b[i];j+=c[i])
                    op^=j;
            }
            for(int i=0;i<n;i++){
                if(op>=a[i]  && op <=b[i] && (op-a[i])%c[i]==0)cnt++;
            }
            if(cnt%2==0)printf("DC Qiang is unhappy.
    ");
            else printf("%d %d
    ",op,cnt);
        }
        return 0;
    }
    


  • 相关阅读:
    c#: List.Sort()实现稳固排序(stable sort)
    c# dt.AsEnumerable ().Join用法
    C#中new的两种用法"public new"和"new public"
    简说设计模式——观察者模式
    mysql中explain的type的解释
    mysql 查询优化 ~explain解读之select_type的解读
    代理
    charle
    like语句防止SQL注入
    java学习网站
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6884424.html
Copyright © 2011-2022 走看看