Codeforces Good Bye 2015 B. New Year and Old Property (DFS)
来源:互联网 发布:上海 手表 知乎 编辑:程序博客网 时间:2024/05/16 05:30
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system —201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros.
The only line of the input contains two integers a andb (1 ≤ a ≤ b ≤ 1018) — the first year and the last year in Limak's interval respectively.
Print one integer – the number of years Limak will count in his chosen interval.
5 10
2
2015 2015
1
100 105
0
72057594000000000 72057595000000000
26
In the first sample Limak's interval contains numbers 510 = 1012,610 = 1102,710 = 1112,810 = 10002,910 = 10012 and1010 = 10102. Two of them (1012 and1102) have the described property.
题意:求a到b之间转换为二进制之后的数中含有1个0的数的个数
思路:DFS
总结:刚开始写还害怕TLE,最后没想到没超
ac代码:
#include<stdio.h>#include<math.h>#include<string.h>#include<stack>#include<queue>#include<vector>#include<iostream>#include<algorithm>#define MAXN 60001#define LL long long#define ll __int64#define INF 0xfffffff#define mem(x) memset(x,0,sizeof(x))#define PI acos(-1)using namespace std;ll n,m;ll ans;void dfs(ll x,ll bz){if(x>m)return;if(x>=n&&x<=m&&bz)ans++;if(bz==0)dfs(x*2,1);dfs(x*2+1,bz);}int main(){while(scanf("%I64d%I64d",&n,&m)!=EOF){ans=0;dfs(1,0);printf("%I64d\n",ans);}return 0;}
- Codeforces Good Bye 2015 B. New Year and Old Property (DFS)
- CodeForces 611B New Year and Old Property(DFS)
- CF Good Bye 2015 B- New Year and Old Property(CF611B)
- Good Bye 2015-New Year and Old Property(二进制暴力枚举)
- CodeForces 611 B. New Year and Old Property(水~)
- codeforces Good Bye 2016-D New Year and Fireworks(dfs)
- codeforces Good Bye 2016-B New Year and North Pole
- CodeForces Good Bye 2016 :C New Year and Rating、D New Year and Fireworks、E New Year and Old Subsequ
- Good Bye 2016D. New Year and Fireworks(dfs)
- Codeforces Good Bye 2016 D. New Year and Fireworks(bfs/dfs)
- CodeForces 611B New Year and Old Property【DFS&&模拟位运算】
- Codeforces Good Bye 2015 C. New Year and Domino (预处理)
- Codeforces Good Bye 2015 E. New Year and Three Musketeers
- 【Codeforces Good Bye 2015】D. New Year and Ancient Prophecy
- codeforces Good Bye 2015 C - New Year and Domino
- codeforces Good Bye 2015 D. New Year and Ancient Prophecy
- codeforces Good Bye 2015 E. New Year and Three Musketeers
- codeforces-Good Bye 2015-New Year and Domino
- 快速搭建TC、易语言、按键注册码系统
- EditText限制输入字符类型的几种方式
- Linux/Unix命令之Ethtool (设置千兆网卡速度及模式)
- iOS 开发:用 Instruments 来检验你的app
- 仿苹果的滑动开关
- Codeforces Good Bye 2015 B. New Year and Old Property (DFS)
- 火狐浏览器安全连接失败解决办法
- CentOS ZendStudio installation
- Dell R730 通过PXE 安装 Debian x64
- Android Framework/base 学习记录
- jdbcTemplate.queryForObject 方法注意
- 专治linux不服——centos6.7下的一些小问题
- 在CentOS 6.6中安装Python2.7和Django的问题
- 中国信息咨询主要类型机构公司经营发展规模