您的位置:首页 > 运维架构

OpenJudge1455 An Easy Problem

2015-10-29 11:34 204 查看
题目:http://noi.openjudge.cn/ch0406/1455/

分析:可得lowbit x=x&-x;n+lowbit(n)即把右数第一串连续1消除并在其前添加一个1,(n^(n+lowbit))/lowbit)>>2即为把剩余1放到末尾。

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
int main()
{
int lowbit;
while(scanf("%d",&n)==1&n!=0)
{
lowbit=n&-n;
printf("%d\n",n+lowbit+(((n^(n+lowbit))/lowbit)>>2));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: