Good Bye 2015 B. New Year and Old Property

题目链接:http://codeforces.com/problemset/problem/611/B

解题思路:

直接暴力推出所有符合条件的。

由进制转换可以知道,二进制只有1个0也就是十进制减去前面任意一个2的次方

然后脑残一样的用了位运算,死都无法表示64位,只能32位,还以为电脑出问题了。。换了pow秒过。。。

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll m,n,i,j,a[100],b[10000],na,nb,c=0,num;
    a[0] = 1;
    for(i=1;i<63;i++){
        a[i] = pow(2,i);
            a[i]+=a[i-1];
        //cout<<a[i]<<endl;
    }
    b[0] = a[0];
    cin>>m>>n;
    for(i=1;i<63;i++){
        for(j=i-1;j>=0;j--){
            num = pow(2,j);
            b[c++] = a[i] - num;
            //cout<<b[c-1]<<endl;
            }
            if(b[c-1]>=n){
                break;
            }
        }
    if(m!=n){
    for(i=0;i<c;i++){
        if(b[i]>=m){
                na=i;
            break;
        }
    }
    for(i=0;i<c;i++){
        if(b[i]>n){
            nb = i;break;
        }
    }
    cout<<nb-na<<endl;
    }
    else{
        int flag = 0;
        for(i=0;i<c;i++){
            if(b[i]==m)
                flag=1;
                //cout<<b[i]<<endl;
        }
        if(flag == 1)
            cout<<"1"<<endl;
        else
            cout<<"0"<<endl;
    }
    return 0;
}
时间: 2024-10-09 16:23:28

Good Bye 2015 B. New Year and Old Property的相关文章

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 的数量是多少. *********************** 首先贴出一段绝对会超时的代码,连提交的勇气都木有呢~因为第四组数据已经接近龟速了,所以...(大家可忽略) 1 #include <iostream> 2 #include <cstdio> 3 #

Good Bye 2015 A. New Year and Days 签到

A. New Year and Days Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015. Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016. Lima

Good Bye 2015 A

Problem A:http://codeforces.com/problemset/problem/611/A A. New Year and Days 题意:某人要在2016年收集糖果,有两种不同的收集方式,按week或month.x表示week的周x或月的x号,只有到每周或每月的x时才会收集一颗糖果,问:在给定的月或周条件内,2016年能收集多少颗糖果. 思路:我是用数组存好,其实也可以更简洁,周的话除了5,6,7是53个,其他都是52个:月的话1-29都是12(闰年),30是11,31是

Good Bye 2015 C. New Year and Domino 二维前缀

C. New Year and Domino They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with h rows and w

JavaSript到目前我学了些什么Part-2

这篇博客这要是string的基本操作,底下这份文件是我看完一个视频教程(需FQ)的练习. 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"/> 5 <title>This is us</title> 6 </head> 7 <body> 8 <p>This file is all about different

阿尔红军我让我特我问题沃特尔行业

http://www.houzz.com/ideabooks/38419124/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419135/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419147/thumbs/2015.01.04 http://www.houzz.com/ideabooks/38419107/thumbs/2015.01.04 http://www.houzz.c

哪敢跟学长这么

不少人面庞上有不由得惊呼出声http://weibo.com/09.16/2015/p/1001603887569338240338http://weibo.com/09.16/2015/p/1001603887569338268443http://weibo.com/09.16/2015/p/1001603887569342462767http://weibo.com/09.16/2015/p/1001603887569342462769http://weibo.com/09.16/2015/

右手缓缓握拢而

火红烈日炸裂的一路冲杀进去吧http://weibo.com/2015/09/16/p/1001603887216807041204http://weibo.com/2015/09/16/p/1001603887216811186273http://weibo.com/2015/09/16/p/1001603887216811186277http://weibo.com/2015/09/16/p/1001603887216811235528http://weibo.com/2015/09/16/

叶轻灵苦笑一声

灵光刚刚收起时灵兵潮流尽数的牧尘准备不错http://weibo.com/2015.09.16/p/1001603887492385369004http://weibo.com/2015.09.16/p/1001603887492389563376http://weibo.com/2015.09.16/p/1001603887492393757752http://weibo.com/2015.09.16/p/1001603887492397975161http://weibo.com/2015.