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. python py_innodb_page_info.py -v /usr/local/var/mysql/ibdata1

    mylib.py #encoding=utf-8 import os import include from include import * TABLESPACE_NAME='D:\\mysql_d ...

  2. shc加密shell脚本

    下载地址:http://www.datsi.fi.upm.es/~frosal/sources/ 安装 .tgz cd shc- mkdir -p /usr/local/man/man1 这步是必须的 ...

  3. java Swing 图片缓冲机制

    java Swing 图片缓冲机制: 参考:http://jorneyr.iteye.com/blog/868858#comments package util; import java.awt.ge ...

  4. log4j.rootLogger详细说明

    http://blog.csdn.net/anlina_1984/article/details/5313023

  5. Python实现字典的key和values的交换

    #encoding=utf-8 #反转字典 即key和val互换 dict1={1:2,3:4,6:7,9:10} print '---生成器表达式' def invert_dict(d): retu ...

  6. python之twisted模块安装

    Twisted是一个事件驱动的网络框架. 最近开始学习了解Twisted,首先肯定要安装twisted模块. 但是在cmd下执行:pip install twisted 出现了下面的问题:" ...

  7. ArcGIS制图表达Representation-规则和几何效果

    ArcGIS制图表达Representation-规则和几何效果 by 李远祥 对制图表达运用是否纯熟,主要是看对制图表达规则的理解和巧妙运用.前面章节已经粗略介绍过制图表达的运用,通过一些简单的规则 ...

  8. JAVA传值与传址

    要了解JAVA中的传值与传址问题,必要先要了解JVA中的栈内存和堆内存,>>>>点些查看<<<<昨天写的学习记录 栈:基本数据类型.数据的引用变量,这两 ...

  9. C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)),不对的地方欢迎指出与交流. 章节出自<Professional C ...

  10. python之列表对象

    1. 获取列表中的某个值 描述:获取下标所对应的值 语法: print(li[0]) #[取索引值] 样例: li = list(['a','b','c']) val=(li[0]) #获取下标所对应 ...