BestCoder Round #79 (div.2) 1002 Claris and XOR
来源:互联网 发布:sql 注入式攻击 编辑:程序博客网 时间:2024/05/29 13:59
题意很简洁,给出两个区间[a,b],[c,d]且a,b,c,d均不超过
1018 一般求最大异或值得解法就是贪心,从高位往低位贪即可,字典树也是这个原理,只不过上者需要O(n)的预处理,这题关键还是要知道若到了某一位两个数0,1均能取,那么后面肯定全为1。这样只要扫一遍就可以了。
#include <iostream>#include <cstdio>#include <map>#include <queue>#include <vector>#include <climits>#include <cstring>#include <cmath>#include <algorithm>#define LL long longusing namespace std;LL a, b, c, d;bool judge(LL l, LL r, LL n, LL m){ if(l < n) { if(r >= n)return true; } if(l >= n && l <= m)return true; return false;}int main(){ int T; scanf("%d", &T); while(T--) { scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d); LL l, r, left , right, ans; l = r = 0LL; bool la, lb, ra, rb; bool flag = false; for(LL i = 60LL; i >= 0LL; --i) { ra = rb = la = lb = false; left = l; right = l + (1LL << i) - 1LL; if(judge(left, right, a, b))la = true; left = l + (1LL << i); right = l + (1LL << (i + 1LL)) - 1LL; if(judge(left, right, a, b))lb = true; left = r; right = r + (1LL << i) - 1LL; if(judge(left, right, c, d))ra = true; left = r + (1LL << i); right = r + (1LL << (i + 1LL)) - 1LL; if(judge(left, right, c, d))rb = true; if(ra && rb && la && lb) { ans = (l ^ r) + (1LL << (i + 1LL)) - 1LL; flag = true; break; } if(ra && lb) { l = l + (1LL << i); continue; } if(rb && la) { r = r + (1LL << i); continue; } if(ra && la) { continue; } if(rb && lb) { l = l + (1LL << i); r = r + (1LL << i); } } if(!flag) ans = l ^ r; cout << ans << endl; } return 0;}
0 0
- BestCoder Round #79 (div.2) 1002 Claris and XOR
- BestCoder Round #79 (div.1) Claris and XOR 题解。。。
- BestCoder Round #79 1002/hdu 5661 Claris and XOR 贪心
- bestcoder 79 Claris and XOR
- 【异或+贪心】HDU5661Claris and XOR【BestCoder Round #79 (div.2)】
- HDU5661---Claris and XOR
- Claris and XOR
- bestcoder Round #79 (div.2)jrMz and angles
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~
- 【BestCoder Round #79 (div.2)】HDU5660jrMz and angles
- BestCoder Round #64 (div.2) 1002 and 1003
- BestCoder Round #83 1004 zxa and xor
- HDU 5661 Claris and XOR
- BC之Claris and XOR
- HDU-5661-Claris and XOR
- HDU 5661 Claris and XOR
- Hdu 5661 Claris and XOR
- HDU 5661 Claris and XOR
- 对vb感受(下)
- [Clean Code] Chapter 6: 数据结构 vs 对象!
- 每个程序员都会犯的十个错误
- 理解堆栈及其利用方法
- 贪心算法☞活动安排
- BestCoder Round #79 (div.2) 1002 Claris and XOR
- 有关Java基础的一些笔试题总结
- Service中onStartCommand()理解
- Tomcat中 server.xml 的Context的配置
- nretraPdroW.290
- 绘图(五,Android图像变换基础知识矩阵Matrix)
- C语言中整型与指针之间转换的注意点
- 【C#】机房重构版---开工
- 中文字符转数字(可能会很大)