Codeforces 276D Little Girl and Maximum XOR【贪心】
来源:互联网 发布:nba马刺vs小牛数据 编辑:程序博客网 时间:2024/05/28 16:11
题目大意:
在区间【L,R】内找到两个数,使得他们的异或值最大。
思路:
①我们从高位开始贪心即可,如果两个数L,R的2进制位数长度不同,设定R的2进制长度为x的话,那么答案一定是(1<<x)-1;因为我们可以让R除了最高位之外,都变成0,让L所有位子都变成1.并且长度为x-1.
②否则,如果两个数长度相等且部分前边高位数值一样的话,我们忽略不计,只找最高位不同的位子即可。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;#define ll __int64int main(){ ll l,r; while(~scanf("%I64d%I64d",&l,&r)) { for(ll i=60;i>=-1;i--) { if(i==-1||((l>>i)^(r>>i))) { printf("%I64d\n",((1ll<<(i+1))-1)); break; } } }}
阅读全文
0 0
- Codeforces 276D Little Girl and Maximum XOR (贪心)
- Codeforces 276D Little Girl and Maximum XOR 贪心+构造
- Codeforces 276D Little Girl and Maximum XOR【贪心】
- D. Little Girl and Maximum XOR(贪心)
- codeforces 276D D. Little Girl and Maximum XOR(贪心+dp+数论)
- Codeforces 276D. Little Girl and Maximum XOR
- Codeforces 276D. Little Girl and Maximum XOR(模拟)
- [CodeForces 276D] Little Girl and Maximum XOR (构造+脑洞)
- CodeForces 276 D.Little Girl and Maximum XOR(位运算)
- codeforces 276D Little Girl and Maximum XOR(区间最大异或值--技巧)【模板】
- Codeforces 276C Little Girl and Maximum Sum【贪心】
- 【Codeforces Round 169 (Div 2) D】【简单数位贪心】Little Girl and Maximum XOR 区间选两数使得异或值尽可能大
- CodeForces 276C Little Girl and Maximum Sum
- Codeforces 276C Little Girl and Maximum Sum
- codeforces 276 C. Little Girl and Maximum Sum
- Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心)
- N - Little Girl and Maximum Sum——贪心
- CF276C Little Girl and Maximum Sum(贪心+差分)
- request.getParameter() 和request.getAttribute() 区别
- 单例设计模式及应用
- org.apache.catalina.LifecycleException: 配置Tomcat问题
- 读《微服务设计》
- Servlet学习,个人理解
- Codeforces 276D Little Girl and Maximum XOR【贪心】
- 全面升级Android面试之热更新问题
- Material Design 你要的都在这里了(持续跟新)
- jdbc中的事务回滚管理
- 获取下个月Java和sql的两种实现
- Java的元组类型整理
- phpstorm 2016.2.1最新版本离线激活方法(内含激活码
- 伪类和伪元素的区别
- hibernate-jpa中@Embeddable注解的类查询