标签:
3
11 2 4
22 3 3
15 2 5
Case #1: 12
Case #2: 25
Case #3: 17
#include <stdio.h> int slove(int d,int s1,int s2){ int next; long end = 1 << 28; for(int i=d+1;i<=end;i++){ int bitCount = 0; for(int j=0;j<31;j++){ if( (i & (1<<j)) > 0) bitCount++; } if(bitCount>=s1 && bitCount <= s2){ next=i; break; } } return next; } int main(){ int n; int d; int s1; int s2; int c = 1; while(scanf("%d",&n)==1){ for(int i=0;i<n;i++){ scanf("%d",&d); scanf("%d",&s1); scanf("%d",&s2); int ret = slove(d,s1,s2); printf("Case #%d: %d\n",c++,ret); } } }
2015年ACM-ICPC亚洲区域赛合肥站网络预选赛H题——The Next (位运算)
标签:
原文地址:http://www.cnblogs.com/dick159/p/5386951.html