zoukankan      html  css  js  c++  java
  • HDU1196 Lowest Bit

    题目链接

    Lowest Bit

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 13926    Accepted Submission(s): 10063


     

    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

    一下就发现一道水题。

    树状数组里举足轻重的求低位函数。实现方式如下,第一种较为常见。

    AC代码:

     1 #include<iostream>
     2 #include<sstream>
     3 #include<algorithm>
     4 #include<string>
     5 #include<cstring>
     6 #include<iomanip>
     7 #include<vector>
     8 #include<cmath>
     9 #include<ctime>
    10 #include<stack>
    11 #include<queue>
    12 #define e 2.71828182
    13 #define Pi 3.141592654
    14 using namespace std;
    15 int lowbit(int x)//常用 
    16 {
    17     return x&(-x);
    18 }
    19 /*int lowbit(int x)
    20 {
    21     return x&(x^(x-1));
    22 }*/
    23 int main()
    24 {
    25     int A; 
    26     while(cin>>A&&A!=0)
    27     {
    28         cout<<lowbit(A)<<endl;
    29     }
    30 }
    View Code
  • 相关阅读:
    Android Studio 如何导入源码
    多版本 jdk 的切换方法
    Markdown的常用语法
    adb常用命令
    虚拟机怎样共享ubuntu中的文件
    adb的相关配置
    【Leetcode】2的幂(整数的二进制形式,与运算)
    【Leetcode】二叉树的最小深度
    【Leetcode】合并两个有序链表
    【Leetcode】国王挖金矿
  • 原文地址:https://www.cnblogs.com/wangzhebufangqi/p/12796131.html
Copyright © 2011-2022 走看看