首页 > 其他 > 详细

hdu 5491 思维题

时间:2018-09-19 01:02:24      阅读:190      评论:0      收藏:0      [点我收藏+]
 #include<stdio.h>
#include <math.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bitset>
#include <iostream>
using namespace std;
#define LL long long
void out(LL x)
{
    bitset<32>s(x);
    cout<<s<<endl;
}
#define cal(x) __builtin_popcountll(x)
int main()
{
    freopen("in.txt","r",stdin);
    int t=1;
    scanf("%d",&t);
    for(int ca=1;ca<=t;ca++)
    {
        LL d,s1,s2;
        scanf("%lld%lld%lld",&d,&s1,&s2);
        d++;
        while(cal(d)<s1||cal(d)>s2)
        {
            for(int i=0;cal(d)<s1;i++)
            {
                d|=1ll<<i; //1的数目小就让低位为1
            }
            for(int i=0;cal(d)>s2;i++)
            {
                if(d&(1ll<<i))
                    d+=1ll<<i;//1的数目多就让其进位为0
            }
        }
        printf("Case #%d: %lld\n",ca,d);
    }
    return 0;
}

 

hdu 5491 思维题

原文:https://www.cnblogs.com/polya/p/9672294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!