Let L denote the number of 1s in integer D's binary representation. Given two integers S1 and S2, we call D a XHY number if S1≤L≤S2.
With a given D, we would like to find the next XHY number Y, which is JUST larger than D. In other words, is the smallest XHY number among the numbers larger than D. Please write a program to solve this problem.


输入要求

The first line of input contains a number T indicating the number of test cases (T≤100000).
Each test case consists of three integers D, S1, and S2, as described above. It is guaranteed that 0≤D<2^28 and D is a XHY number.

输出要求

For each test case, output a single line consisting of “Case #X: Y”. X is the test case number starting from 1. Y is the next XHY number.

测试数据示例

输入

3
11 2 4
22 3 3
15 2 5

输出

Case #1: 12
Case #2: 25
Case #3: 17

 
大水题,开始以为会TLE,结果暴力搞一下位运算就过了,主要是题目有难懂。
 
题目意思大概如下:
L代表整数D的二进制位为1的个数。譬如D=3,L=2。
假如s1<=L<=s2,则D就是XHY数。现在就是要你找出大于D的最小XHY数。
 
题目明白了之后就是很裸的按位与(&)操作。
 
上代码了.
C code
 
#include <stdio.h>

int slove(int d,int s1,int s2){
int next;
long end = << ;
for(int i=d+;i<=end;i++){
int bitCount = ;
for(int j=;j<;j++){
if( (i & (<<j)) > ) bitCount++;
}
if(bitCount>=s1 && bitCount <= s2){
next=i;
break;
}
}
return next;
}
int main(){
int n;
int d;
int s1;
int s2;
int c = ;
while(scanf("%d",&n)==){
for(int i=;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 (位运算)的更多相关文章

  1. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  2. 2014ACM/ICPC亚洲区域赛牡丹江站汇总

    球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...

  3. Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)

    题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...

  4. Digit sum (第 44 届 ACM/ICPC 亚洲区域赛(上海)网络赛)进制预处理水题

    131072K   A digit sum S_b(n)Sb​(n) is a sum of the base-bb digits of nn. Such as S_{10}(233) = 2 + 3 ...

  5. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation

    Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation ...

  6. 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)

    Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...

  7. 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)

    题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...

  8. 【2018 ICPC亚洲区域赛徐州站 A】Rikka with Minimum Spanning Trees(求最小生成树个数与总权值的乘积)

    Hello everyone! I am your old friend Rikka. Welcome to Xuzhou. This is the first problem, which is a ...

  9. 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)

    Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...

随机推荐

  1. php中cookie实现二级域名可访问操作的方法

    本文实例讲述了php中cookie实现二级域名可访问操作的方法.分享给大家供大家参考.具体方法如下: cookie在一些应用中很常用,假设我有一个多级域名要求可以同时访问主域名绑定的cookie,下面 ...

  2. Goldengate双向复制配置

    一.Goldengate双向复制配置 1.1.在进行如下配置之前,先在源数据库source system(原来的目标数据库)端 添加辅助的redolog配置: SQL>alter databas ...

  3. C实现类、继承、多态

    首先考虑用C实现类 肯定是要使用struct的,类的数据成员放在struct里面: 而类有构造函数.析构函数,这两个函数必须在struct外面,构造函数要分配struct空间并初始化struct成员, ...

  4. 通过浏览器navigator判断浏览器版本或者手机类型&&判断微信访问

    javascript 的navigator属性,不常用,但是用处也不少,主要用处是在做浏览器兼容的问题的时候,现在有的网站已经不兼容IE6,用户假如用IE6浏览网页的话,会提示浏览器升级等信息.或者判 ...

  5. Javascript中的async await

    async / await是Javascript是ES7的重要特性之一,也是目前社区里公认的优秀异步解决方案.目前,async / await这个特性已经是stage 3的建议,可以看看TC39的进度 ...

  6. Oracle 11g 的安装及配置详解

    一.安装前的准备: 首先在这里给出本人的百度网盘的链接:http://pan.baidu.com/s/1c1WF1PQ:网速快的小伙伴建议到官网:http://www.oracle.com/techn ...

  7. 《InsideUE4》UObject(四)类型系统代码生成

    你想要啊?想要你就说出来嘛,你不说我怎么知道你想要呢? 引言 上文讲到了UE的类型系统结构,以及UHT分析源码的一些宏标记设定.在已经进行了类型系统整体的设计之后,本文将开始讨论接下来的步骤.暂时不讨 ...

  8. jQuery + CSS3实现环形进度条

    实现原理 原理非常的简单,在这个方案中,最主要使用了CSS3的transform中的rotate和CSS3的clip两个属性.用他们来实现半圆和旋转效果. 半环的实现 先来看其结构. HTML < ...

  9. WebServerice的发布

    在webserverice一文中,我们简单的介绍了一下什么是webserverice,以及如何建立一个webserverice服务.今天,我们一起学习下webserverice是如何发布的. 为什么要 ...

  10. shell编程其实真的很简单(五)

    通过前几篇文章的学习,我们学会了shell的基本语法.在linux的实际操作中,我们经常看到命令会有很多参数,例如:ls -al 等等,那么这个参数是怎么处理的呢? 接下来我们就来看看shell脚本对 ...