codeforces Good Bye 2015 B. New Year and Old Property
题目链接:http://codeforces.com/problemset/problem/611/B
题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制数表示只有 1 个 0 的数量是多少。
***********************
首先贴出一段绝对会超时的代码,连提交的勇气都木有呢~因为第四组数据已经接近龟速了,所以。。。(大家可忽略)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; typedef __int64 ll;
ll a, b;
ll ans; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%I64d%I64d", &a, &b) != EOF) {
__int64 i;
ans = ; for (i = a; i <= b; i++) {
__int64 l = i;
int c = ;
while (l && c <= ) {
c += ((l & ) == ? : );
l >>= ;
}
if (c == )
ans++; }
printf("%I64d\n", ans);
}
return ;
}
***********************
讲讲正确的解题思路 —— 就是暴力枚举啦.......当然不是将十进制数先化成二进制数再慢慢比对啦,我上面的代码就类似这个思想了,讲多都是泪,呜呜呜~~~
是模拟二进制数,在 [1, 10^18] 范围内,统计出只出现二进制表示0只出现1次的数
我还是第一次知道原来可以这样算= =、、、 慢慢积累经验吧~~~
另外讲一讲数的范围, 2^61 已经比 10^18要大了,所以枚举的时候,举例到61次就行,代码有详尽的注释,大家慢慢欣赏 ^_^
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; typedef __int64 ll;
const int bit = ; // 2^61 = 1,152,921,504,606,846,976 int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE ll a, b;
while (scanf("%I64d%I64d", &a, &b) != EOF) {
int ans = ; for (int i = ; i <= bit; i++) {
ll mea = (1ll << i) - ; // 1, 11, 111, 1111, ... for (int j = ; j < i-; j++) {
ll t = mea - (1ll << j); // (1ll<<j): 1, 10, 100, 1000, ...
ans += (t >= a && t <= b);
}
}
printf("%d\n", ans);
}
return ;
}
codeforces Good Bye 2015 B. New Year and Old Property的更多相关文章
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
- Codeforces Good Bye 2015 C. New Year and Domino 前缀和
C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...
- Good Bye 2015 B. New Year and Old Property —— dfs 数学
题目链接:http://codeforces.com/problemset/problem/611/B B. New Year and Old Property time limit per test ...
- Good Bye 2015 B. New Year and Old Property 计数问题
B. New Year and Old Property The year 2015 is almost over. Limak is a little polar bear. He has re ...
- good bye 2015 B - New Year and Old Property
题意:统计在n,m之间的数的二进制表示形式只有一个零的数目. 位运算模拟+dfs #include<iostream> #include<string> #include< ...
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
随机推荐
- 15个初学者必看的基础SQL查询语句
本文由码农网 – 小峰原创翻译,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 本文将分享15个初学者必看的基础SQL查询语句,都很基础,但是你不一定都会,所以好好看看吧. 1.创建表和数据插 ...
- python __future__ package的几个特性
我学习python过程, 和学习其它编程知识一样, 不是先读大部头书系统学习, 而是看博客和直接实践, 慢慢将这些知识点连成线, 再扩展到面. 这个过程缺点和优点都很明显. 缺点是, 有些知识点可能因 ...
- PHP缓存机制Output Control详解
开启OB缓存的方式有如下两种: 1. php.ini中开启 output_buffering = 4096 启用了此指令,那么每个PHP脚本都相当于一开始就调用了ob_start()函数,PHP5.5 ...
- WCF binding的那些事!!!
原文地址:http://www.cnblogs.com/Anima0My/archive/2008/04/16/1156146.html WCF中常用的binding方式: BasicHttpBind ...
- gdb调试core文件
本人最近正在学习调试技术,此处对栈溢出做一些总结. gdb的基本使用就不多扯了. 主要针对发行在外的release版本的软件出现问题时的调试. 一般来讲,查看堆栈就是使用bt,这个时候加上bt ful ...
- [Storm] java.io.FileNotFoundException: File '../stormconf.ser' does not exist
This bug will kill supervisors Affects Version/s: 0.9.2-incubating, 0.9.3, 0.9.4 Fix Version/s: 0.10 ...
- .Net程序员必须要知道的东西之HttpModules与HttpHandlers介绍
一.ASP.NET对请求处理的过程: 当客户端请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给ASPNET_ISAPI. ...
- 遇到了IAR烧写程序出错,附解决办法The stack plug-in failed to set a breakpoint on "main"
今天做无线串口调试的时候用IAR7.51往CC2530无线模块烧程序的时候遇到了问题: 先是下载过程中有许多警告,然后就是提示无法跳断点,找不到main方法,每次烧程序都出现: The stack p ...
- 使一个div始终显示在页面中间
使一个div始终显示在页面中间 假设我们有一个div层:<div id=”myDiv”></div> 首先,我们用css来控制它在水平上始终居中,那么我们的css代码应该是这样 ...
- 支付安全基础 —— HTTPS的故事
本文主要讲述了HTTPS的基本原理,通过HTTPS握手过程.证书链.中间人攻击.CA机构等问题,详细解释了百付宝系统中用到的HTTPS安全知识,同时,介绍了如何查看www.baifubao.com的 ...