题目链接: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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. good bye 2015 B - New Year and Old Property

    题意:统计在n,m之间的数的二进制表示形式只有一个零的数目. 位运算模拟+dfs #include<iostream> #include<string> #include< ...

  8. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  9. Codeforces:Good Bye 2018(题解)

    Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...

随机推荐

  1. django book

    一.安装配置 1.下载地址: https://www.djangoproject.com/download/ 2.安装: tar zxvf Django-1.6.1.tar.gz && ...

  2. Javaee----重新回顾servlet

    最近面临找工作,不得不回顾一下java servelt . 发现lz的基本功还是很差 1. 每一个servlet都必须实现servlet接口,GenericServlet是个通用的.不特定于任何协议的 ...

  3. Linux下Redis常用命令

    >src/redis-server  启动 Redis 服务  或者>src/redis-server redis.conf src/redis-server redis.conf 1&g ...

  4. PHP基础之 继承(一)

    ========================================= *                 继承 extends *============================ ...

  5. 扁平化设计五大原则(转自CSDN翻译)

    Cousins表示他虽然对扁平化设计的感觉非常强烈,但并没有特别热爱或者特别讨厌扁平化设计.他认为好的设计不应当局限于某种设计风格,而需要更注重可用性.有用性.如果因为时尚的缘故,那就顺其自然吧.但该 ...

  6. hdu.1429.胜利大逃亡(续)(bfs + 0101011110)

    胜利大逃亡(续) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  7. 【PHP面向对象(OOP)编程入门教程】15.static和const关键字的使用(self::)

    static关键字是在类中描述成员属性和成员方法是静态的:静态的成员好处在哪里呢?前面我们声明了“Person”的人类,在“Person”这个类里如果我们加上一个“人所属国家”的属性,这样用“Pers ...

  8. 类调用类的protected或private的成员函数或成员变量

    1.在其中一个类定义友元函数,则可以实现该类直接使用另外类的里所有内容. 一般实例化两个类,友元类以及自身类,实现友元类传递指针到自身类 2.如果两个类是可以继承的关系,则在子类里继承该类,实现在子类 ...

  9. maven引入jar包时,一个jar的引入错误,会导致后来的jar包的引入。

    maven引入本jar包时,引入失败. 问题是另一个jar没有引入正确.

  10. Codeforces 260 A - A. Laptops

    题目链接:http://codeforces.com/contest/456/problem/A 解题报告:有n种电脑,给出每台电脑的价格和质量,要你判断出有没有一种电脑的价格小于另一种电脑但质量却大 ...