题目链接

这题真的体现了自己思维的不足,考虑问题只是考虑他的特殊性,却不能总结出它的一般性规律。

对于这题, 如果L == R , 那么结果为0.

否则, 我们只需要找到最高的某一位 (二进制数中的某一位, 设为第p位, 从0开始编号),

使得要找的两个数从最高位到最低位, 在第p位第一次出现不同,如 11110000 和 11101111, 这里 p = 4.

这样,结果就是 (2^p) ^ (2^p -1)

附上代码:

 l, r = map(long, raw_input().split())
if l == r:
print 0
else:
p = 0
for i in xrange(61):
if ((1 << i) & r > 0) and ((1 << i) & l) == 0:
p = i
print (1 << p) ^ ((1 << p) - 1)

Codeforces 276D的更多相关文章

  1. Codeforces 276D Little Girl and Maximum XOR

    题意:给范围l,r选两个数亦或最大是多少. 思路:找到第一个l和r二进制下不相同的位置i,然后答案就是2^(i+1)-1,因为一个取0一个取1之后,后面的位置全部选1和全部选0,就是这样:011111 ...

  2. CodeForces 276D – Little Girl and Maximum XOR 贪心

    整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Luogu P2864 [USACO06JAN]树林The Grove(bfs)

    P2864 [USACO06JAN]树林The Grove(bfs) 题面 题目描述 The pasture contains a small, contiguous grove of trees t ...

  2. 跟我一起了解koa(三)

    跟我一起了解koa中间件 一.是 什么是 Koa 的中间件 通俗的讲: :中间件就是匹配路由之前或者匹配路由完成做的一系列的操作,我们就可以 把它叫做中间件. 在 在express件 中间件( (Mi ...

  3. [Array]1. Two Sum(map和unorder_map)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. iBaties对比hibernate

    翻译至一篇2008年的文章(http://www.javaworld.com/article/2077875/open-source-tools/ibatis--hibernate--and-jpa- ...

  5. CentOS7 下的 firewall 用法

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

  6. R语言中如何使用最小二乘法

    R语言中如何使用最小二乘法 这里只是介绍下R语言中如何使用最小二乘法解决一次函数的线性回归问题.         代码如下: > x<-c(6.19,2.51,7.29,7.01,5.7, ...

  7. 解决前端跨域请求(SpringBoot)

    @Configuration public class CorsConfig { private CorsConfiguration buildConfig() { CorsConfiguration ...

  8. linux挂载点 和 文件系统$ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */

    $ mount$ cat /etc/fstab$ vgs$ pvs$ lvs$ df -h$ lsof +D / /* beware not to kill your box */ 一共挂载了多少文件 ...

  9. tcpdump的表达式介绍

    表达式是一个正则表达式,tcpdump利用它作为过滤报文的条件,如果一个报文满足表 达式的条件,则这个报文将会被捕获.如果没有给出任何条件,则网络上所有的信息包 将会被截获. 在表达式中一般如下几种类 ...

  10. Django与HTML业务基本结合--基本的用户名密码提交方法2

    from django.shortcuts import render # Create your views here. from django.shortcuts import render de ...