hdu 5491 思维题
发布时间:2020-12-14 03:45:29 所属栏目:大数据 来源:网络整理
导读:#includestdio.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_popco
#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: %lldn",ca,d); } return 0; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |