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. PHP图像操作:3D图、缩放、旋转、裁剪、加入水印(一)

    来源:http://www.ido321.com/875.html 1.利用php gd库的函数绘制3D扇形统计图 1: <?php 2: header("content-type&q ...

  2. [ES6] 11. String Templates

    ECMAscript 6 lets us use string templates to gain a lot more control over strings in JavaScript. var ...

  3. VC在windows中打开文件夹并选中文件

    网上一位前辈高人的一段精髓代码让我眼前一亮…… ShellExecute(NULL, "open", "explorer.exe", "/select ...

  4. Tomcat的server.xml配置讲解(一)

    一.Tomcat虚拟目录的配置 1.服务器配置 默认端口号为8080,如果要想修改端口号,则可以在Tomcat目录中的conf/server.xml文件,找到如下代码,将端口号改为:80:保存serv ...

  5. js 因加入form导致两个table之间出现空白问题

    在<FORM>中加CSS <table> ....... </table> <form style="padding:0; margin:0;&qu ...

  6. 《暗黑世界V1.4》API说明文档

    <暗黑世界V1.4>API说明文档 阵法位置示意图 上方:                        下方:      账号注册   100 请求信息 { username   str ...

  7. 安装Vagrant出错 安装Homestead出错失败

    安装Vagrant出错 安装Homestead出错     我们也可以在电脑上创建其它文件夹,只需保证创建的文件夹路径跟 Homestead.yaml 文件中的 folders - map 保持一致即 ...

  8. Ubuntu 下apache2 增加新的module

    http://andrew913.iteye.com/blog/398648 首先来介绍下apache的一个工具apxs.apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译 ...

  9. 【DB2】在使用EXISTS时,查询结果中包含聚合函数,一个不注意就会犯错的坑

    需求描述 现在需要通过EXISTS中的语句来控制查询结果是否存在 第一次实现SQL SELECT 1 AS ID,SUM(1) FROM (SELECT ID,NAME FROM (VALUES(1, ...

  10. mysql表属性、索引、约束

    1.表属性 创建表的基本语法: create table [if not exists] 表名 (字段列表 [,索引或约束列表])[表选项列表] 其中,字段列表格式如下: 字段名 类型 [属性列表], ...