zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    CentOS 7
    CentOS
    CentOS 7
    CentOS 7
    Linux目录结构说明
    CentOS 7
    CentOS 7
    Linux——工具参考篇
    Linux工具进阶
    Selenium——UI自动化测试(2)——How to Download & Install Selenium WebDriver (待续)
  • 原文地址:https://www.cnblogs.com/kls123/p/7126944.html
Copyright © 2011-2022 走看看