Lowest Bit


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Given an positive integer A (1 <= A <= 100), output the lowest bit of A.

For example, given A = 26, we can write A in binary form as 11010, so the lowest bit of A is 10, so the output should be 2.

Another example goes like this: given A = 88, we can write A in binary form as 1011000, so the lowest bit of A is 1000, so the output should be 8.

Input

Each line of input contains only an integer A (1 <= A <= 100). A line containing "0" indicates the end of input, and this line is not a part of the input data.

Output

For each A in the input, output a line containing only its lowest bit.

Sample Input

26

88

0



Sample Output

2

8


———————————————————————————————————

题目的意思是给出一个n,求出n化为2进制后从低位开始第一个1代表的数

思路:无

AC代码1:化成2进制

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f int main()
{
int n;
int a[100];
while(~scanf("%d",&n)&&n)
{
int len=0;
while(n)
{
a[len++]=n%2;
n/=2;
}
int ans=1;
for(int i=0;i<len;i++)
{
if(!a[i]) ans*=2;
else break;
}
printf("%d\n",ans);
}
return 0;
}

AC代码2:利用计算机补码快速算,树状数组原理

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <functional>
#include <bitset>
#include <string> using namespace std; #define LL long long
#define INF 0x3f3f3f3f int lowbit(int x)
{
return x&-x;
} int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
printf("%d\n",lowbit(n));
}
return 0;
}

ZOJ2417 Lowest Bit 2017-04-18 20:53 38人阅读 评论(0) 收藏的更多相关文章

  1. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  2. House Robber 分类: leetcode 算法 2015-07-09 20:53 2人阅读 评论(0) 收藏

    DP 对于第i个状态(房子),有两种选择:偷(rob).不偷(not rob) 递推公式为: f(i)=max⎧⎩⎨⎪⎪{f(i−1)+vali,f(i−2)+vali,robi−1==0robi−1 ...

  3. hdu3333 Turing Tree 2016-09-18 20:53 42人阅读 评论(0) 收藏

    Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  4. 如何在hadoop中控制map的个数 分类: A1_HADOOP 2015-03-13 20:53 86人阅读 评论(0) 收藏

    hadooop提供了一个设置map个数的参数mapred.map.tasks,我们可以通过这个参数来控制map的个数.但是通过这种方式设置map的个数,并不是每次都有效的.原因是mapred.map. ...

  5. 使用ganglia监控hadoop及hbase集群 分类: B3_LINUX 2015-03-06 20:53 646人阅读 评论(0) 收藏

    介绍性内容来自:http://www.uml.org.cn/sjjm/201305171.asp 一.Ganglia简介 Ganglia 是 UC Berkeley 发起的一个开源监视项目,设计用于测 ...

  6. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  7. NYOJ-102 次方求模 AC 分类: NYOJ 2014-02-06 18:53 184人阅读 评论(0) 收藏

    地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=102 //a^b mod c=(a mod c)^b mod c很容易设计出一个基于二分的递归 ...

  8. ZEDBOARD启动自启配置(加载镜像) 分类: OpenCV ubuntu shell ZedBoard Eye_Detection 2014-11-08 18:53 167人阅读 评论(0) 收藏

    参考:陆书14.2.8 1)备份ramdisk8M.image.gz 2)加载rootfs镜像文件: 3)在镜像目录下建立自己所需文件夹(挂载目录): 我需要的挂载目录有两个: root/qt/ins ...

  9. Hdu1560 DNA sequence(IDA*) 2017-01-20 18:53 50人阅读 评论(0) 收藏

    DNA sequence Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

随机推荐

  1. 遇到的IE不兼容问题总结

    IE浏览器兼容问题困扰多时,由于IE6不在进行修补,IE6的考虑也越来越少,有些IE遇到的不兼容的现象想做一个总结 1宽度或高度:IE的是width+border+margin+padding goo ...

  2. eclispe 通过git向码云上传

    本文将介绍如何将本地的项目提交到开源中国上去,过程比较详细,实现起来很简单.由于自己也算是一个新手,所以没有做过多的解释,只是单纯的描述了该如何去做. 1.在开源中国上面新建一个空项目 到这里也就结束 ...

  3. window环境mysql解压版配置

    1.下载并解压 到官网下载mysql-5.5.10-win32.zip,然后将mysql解压到任意路径,如:C:\mysql-5.5.10-win32 2.设置环境变量 打开计算机->属性-&g ...

  4. AtomEye的使用

    网易博客粗略地在转载的基础上对AtomEye补充了概述: AtomEye: Atomistic configuration viewer developed by J. Li. This progra ...

  5. 兼容多浏览器的网页复制插件(ZeroClipboard)

    前言: 常规利用JS编写的网页复制功能是最简单的方法,但是只对IE有效,无法做到兼容其它浏览器,对其他浏览器也就只能弹窗提示用户手动复制了. <script type="text/ja ...

  6. VMware安装win7:units specified don't exist问题

    主要是磁盘接口不匹配,调整CD/DVD和硬件磁盘接口, CD/DVD调整成IDE,硬盘调整成SATA即可. 提示system not found,主分区没有激活,进入disgenius,会提示修正,保 ...

  7. ios 打tag

    修改spec文件的version: git commit -am"version 0.1.1" git push origin master -u git tag 0.1.1 gi ...

  8. win 下 apache 虚拟主机配置方式

    虚拟主机的配置在apache安装目录下/conf/extra/httpd-vhosts.conf文件中,需要在/conf/httpd.conf中开启. LoadModule vhost_alias_m ...

  9. vsftp上传文件出现553 Could not create file

    没有权限创建文件或是目录,原因是selinux引起的登陆问题. 通过如下命令查看状态: > sestatus -b|grep ftp 设置allow_ftpd_full_access为on. 在 ...

  10. db2表空间及日志文件调整

    1.SQLState '57011' and errorCode '-964'  原因:数据库的日志文件已满  解决方法:修改日志文件大小(加大),增加日志文件个数,增加辅助日志文件个数(三个修改参数 ...