标签:blog http io os for sp 2014 on log
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.\n"); else printf("%d %d\n",op,cnt); } return 0; }
标签:blog http io os for sp 2014 on log
原文地址:http://blog.csdn.net/u011026968/article/details/40374925