Lowest Bit

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7728    Accepted Submission(s): 5674
Problem Description
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

树状数组要用到这个知识点。

#include <stdio.h>

int main()
{
int n;
while(scanf("%d", &n), n){
printf("%d\n", n & (-n));
}
return 0;
}

HDU1196 Lowest Bit的更多相关文章

  1. [LeetCode] Lowest Common Ancestor of a Binary Tree 二叉树的最小共同父节点

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  2. [LeetCode] Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最小共同父节点

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  3. 48. 二叉树两结点的最低共同父结点(3种变种情况)[Get lowest common ancestor of binary tree]

    [题目] 输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点. 二叉树的结点定义如下:  C++ Code  123456   struct BinaryTreeNode {     int ...

  4. [LeetCode]Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  5. 数据结构与算法(1)支线任务4——Lowest Common Ancestor of a Binary Tree

    题目如下:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, fin ...

  6. Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  7. Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  8. leetcode 235. Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  9. leetcode 236. Lowest Common Ancestor of a Binary Tree

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

随机推荐

  1. UML分析设计顺序

    1.用例图:最简单的模型,与设计无关 2.活动图:类似流程图 3.用例图:对1的细化,分解后的Actor及Use Case 4.用例图:分解后的Actor及抽取的数据实体 5.类图:数据结构图 6.顺 ...

  2. 浏览器兼容性问题解决方案之CSS,已在IE、FF、Chrome测试

    当前主浏览器的核心是什么? 1) Trident:IE浏览器使用的内核,该内核程序在1997年的IE4中首次被采用,是微软在Mosaic代码的基础之上修改而来的,并沿用到目前的 IE7.Trident ...

  3. ssh远程连接

    SSH 是Secure Shell protocol 的简写,经由将联机的封包加密的技术,来进行资料的传递,安全. telnet: tcp:23 基于字符 任意客户端登录远程服务器 明文 无需验证 易 ...

  4. 解决tomcat提交的数据乱码的问题

    有时,开发过程中会遇到前端传入“中文”并返回时,会出现乱码!主要是因为前端通过tomcat7提交的数据就出现了乱码的问题,也就说根源在于tomcat7. 有2中方案解决该问题: (1)使用tomcat ...

  5. HTML5 移动端如何使用css让百分比布局的弹窗水平和垂直方向上居中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 基于Vue的数字输入框组件开发

    1.概述 Vue组件开发的API:props.events和slots 2.组件代码 github地址:https://github.com/MengFangui/VueInputNumber 效果: ...

  7. CSS总结:

    给一个div加上边框,为了让他能看到边框,给他加上颜色 border: 2px solid; border-color: #00a1e9; solid表示实线边框.没有这个看不到边框. {border ...

  8. Thread.sleep(0)的作用

    我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确的理解这个函数的用法呢?思考下面这两个问题: 假设现在是 2008-4-7 12:00:00.000,如果我调用 ...

  9. JS回调函数全解析教程(callback)

    自学jQuery的时候,看到一英文词(Callback),顿时背部隐隐冒冷汗.迅速google之,发现原来中文翻译成回调.也就是回调函数了.不懂啊,于是在google回调函数,发现网上的中文解释实在是 ...

  10. vue.js使用之计算属性与方法返回的差别

    <!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@2.4.2&quo ...