2015年ACM-ICPC亚洲区域赛合肥站网络预选赛H题——The Next (位运算)
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, Y 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
#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 (位运算)的更多相关文章
- 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)
队名:Unlimited Code Works(无尽编码) 队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...
- 2014ACM/ICPC亚洲区域赛牡丹江站汇总
球队内线我也总水平,这所学校得到了前所未有的8地方,因为只有两个少年队.因此,我们13并且可以被分配到的地方,因为13和非常大的数目.据领队谁oj在之上a谁去让更多的冠军.我和tyh,sxk,doub ...
- Known Notation括号匹配类问题(2014年ACM/ICPC 亚洲区域赛牡丹江)
题意: 给你数字或 * 的串,你可以交换一个*和数字.在最前面添1.在一个地方插入*,问你使串满足入栈出栈的(RNP)运算法则. 思路: 引用:https://blog.csdn.net/u01158 ...
- 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 ...
- 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation
Known Notation Time Limit: 2 Seconds Memory Limit: 65536 KB Do you know reverse Polish notation ...
- 【2013 ICPC亚洲区域赛成都站 F】Fibonacci Tree(最小生成树+思维)
Problem Description Coach Pang is interested in Fibonacci numbers while Uncle Yang wants him to do s ...
- 【2018 ICPC亚洲区域赛南京站 A】Adrien and Austin(博弈)
题意: 有一排n个石子(注意n可以为0),每次可以取1~K个连续的石子,Adrien先手,Austin后手,若谁不能取则谁输. 思路: (1) n为0时的情况进行特判,后手必胜. (2) 当k=1时, ...
- 【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 ...
- 【2018 ICPC亚洲区域赛沈阳站 L】Tree(思维+dfs)
Problem Description Consider a un-rooted tree T which is not the biological significance of tree or ...
随机推荐
- HDU1848-Fibonacci again and again
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1848 这个题目代码不是很复杂,但那个等价类,(SG函数)没怎么理解, 题目难,不过代码不怎么复杂,在网 ...
- 腾讯面试题:10G 个整数,乱序排列,要求找出中位数。内存限制为 2G。
腾讯面试题:10G 个整数,乱序排列,要求找出中位数.内存限制为 2G. 题目和基本思路都来源网上,本人加以整理. 题目:在一个文件中有 10G 个整数,乱序排列,要求找出中位数.内存限制为 2G.只 ...
- Java Swing Graphics Graphics2D的一般用法
Java Swing Graphics Graphics2D的一般用法: 贝塞尔曲线参考:http://www.zhangxinxu.com/wordpress/2014/06/deep-unders ...
- [MyBatis]mapperLocations属性通配符的使用
http://blog.csdn.net/szwangdf/article/details/23432783 http://ljhzzyx.blog.163.com/blog/static/38380 ...
- .net判断System.Data.DataRow中是否包含某列
大家对将DataRow转成实体对象并不陌生,转成实体的时候一般都会加上这个判断 if (row["字段名"] != null && row["字段名&q ...
- C++ 头文件系列(vector)
简介 vector头文件包含vector的类模版以及该模版的显示特化版本vector< bool >. vector是C++容器库中非常通用的一种容器,如果你不知道该决定使用哪一种容器,或 ...
- MEAN教程1-MongoDB安装和使用
MEAN是MongoDB.Express.AngularJS和Node.js的缩写.其理念是仅使用JavaScript一种语言来驱动整个应用.其最鲜明的特点有以下几个:1整个应用只使用一种语言:2整个 ...
- 2017-01-27-hibernate环境搭建
Hibernate的环境搭建(uid方式): 1:导入包 2:创建实体对象 3:hibernate的映射配置文件 4:hibernate的核心配置文件 5:创建测试类实现表的创建 2:创建实体对象-U ...
- ubuntu14.04下手动安装eclipse
ubuntu14.04下手动安装eclipse 第一步: 安装jdk 第二步: 下载eclipse,假设下载的文件文件名为eclipse.tar.gz 第三步: 解压 sudo -zxvf ./ecl ...
- button快速点击造成多次相应的解决办法
UIButton+touch.h #import <UIKit/UIKit.h> #define defaultInterval 3 //默认时间间隔 @interface UIButto ...