码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5491 思维题

时间:2018-09-19 01:20:09      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:amp   int   ase   txt   print   uil   \n   namespace   ++   

 #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 思维题

标签:amp   int   ase   txt   print   uil   \n   namespace   ++   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!