[poj 2453] An Easy Problem
An Easy Problem
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 8371 | Accepted: 5009 |
Description
Given a positive integer I, you task is to find out an integer J, which is the minimum integer greater than I, and the number of '1's in whose binary form is the same as that in the binary form of I.
For example, if "78" is given, we can write out its binary form, "1001110". This binary form has 4 '1's. The minimum integer, which is greater than "1001110" and also contains 4 '1's, is "1010011", i.e. "83", so you should output "83".
Input
A line containing a number "0" terminates input, and this line need not be processed.
Output
Sample Input
1 2 3 4 78 0
Sample Output
2 4 5 8 83
Source
#include<cstdio>
using namespace std;
int n,m,cnt;
int calc(int x){
x=(x&)+((x>>)&);
x=(x&)+((x>>)&);
x=(x&)+((x>>)&);
x=(x&)+((x>>)&);
x=(x&)+((x>>)&);
return x;
}
int main(){
while (scanf("%d",&n)&&n){
cnt=calc(n),n++;
while (calc(n)!=cnt) n++;
printf("%d\n",n);
}
;
}
[poj 2453] An Easy Problem的更多相关文章
- [POJ] 2453 An Easy Problem [位运算]
An Easy Problem Description As we known, data stored in the computers is in binary form. The probl ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- POJ 2826 An Easy Problem? 判断线段相交
POJ 2826 An Easy Problem?! -- 思路来自kuangbin博客 下面三种情况比较特殊,特别是第三种 G++怎么交都是WA,同样的代码C++A了 #include <io ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
- POJ 2826 An Easy Problem?! --计算几何,叉积
题意: 在墙上钉两块木板,问能装多少水.即两条线段所夹的中间开口向上的面积(到短板的水平线截止) 解法: 如图: 先看是否相交,不相交肯定不行,然后就要求出P与A,B / C,D中谁形成的向量是指向上 ...
- POJ 2826 An Easy Problem?! 好的标题
受该两块木板以形成槽的效果.Q槽可容纳雨水多,注意雨爆跌,思想是非常easy,分类讨论是有点差. 1.假定两条线段不相交或平行,然后再装0: 2.有一个平行x轴.连衣裙0. 3.若上面覆盖以下的,装0 ...
- POJ 2826 An Easy Problem!(简单数论)
Description Have you heard the fact "The base of every normal number system is 10" ? Of co ...
- 简单几何(线段相交) POJ 2826 An Easy Problem?!
题目传送门 题意:两条线段看成两块木板,雨水从上方往下垂直落下,问能接受到的水的体积 分析:恶心的分类讨论题,考虑各种情况,尤其是入口被堵住的情况,我的方法是先判断最高的两个点是否在交点的同一侧,然后 ...
随机推荐
- 4、iptables扩展匹配及网络防火墙功能
关于centos7 firewalld http://www.ibm.com/developerworks/cn/linux/1507_caojh/index.html 如何保存及重载规则: ...
- python3.6配置libsvm2.2
参考自:https://blog.csdn.net/weixin_35884839/article/details/79398085 由于需要使用到libsvm,所以开始配这个,所幸一次性就成功了. ...
- 主键非自增列 EF 插入数据库引起的 ID 列不能为 NULL 的错误
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<PostBo ...
- SVN服务器搭建和使用教程
安装SVNserver 点击Next下一步,如下: 然后再点击Next项,下一步,如下: 点击[Next] 如下: Location是指VisualSVN Server的安装目录,Repository ...
- vue--移动端兼容问题
click的300ms延迟: 引入fastclick库来解决 输入命令 npm install fastclick 在main.js导入 import Vue from 'vue' import Ap ...
- 基于 Python 和 Pandas 的数据分析(7) --- Pickling
上一节我们介绍了几种合并数据的方法. 这一节, 我们将重新开始不动产的例子. 在第四节中我们写了如下代码: import Quandl import pandas as pd fiddy_states ...
- 数据从mysql迁移至oracle时知识点记录(一)
最近在做数据的迁移,再将数据从mysql迁移至oracle时,部分sql语句进行了修改,在此对部分知识点进行记录: 参考资料:https://dev.mysql.com/doc/refman/5.5/ ...
- onpause 与 onresume
- Redis 图形化监控方案 RedisLive
一款开源的 Redis 图形化监控工具,界面如图所示 安装 首先安装python2 一般情况下系统自带 然后安装pip2 https://www.cnblogs.com/sea-stream/p/10 ...
- c# 写入Xml 元素(<![CDATA[ ]]>)
一般处理程序代码: XmlDocument xmldoc = new XmlDocument(); xmldoc.AppendChild(xmldoc.CreateXmlDec ...