HDOJ 1196 Lowest Bit

【题意】:给一个数,找其二进制的最低位n,输出2^n。比如 11010为10输出2,11000 is 1000输出8。

思路:按照二进制算法来就行。注意是%2不是/2。

【AC代码】:

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

#define MAX 10

int main()
{
    int n = 0;
    while (cin >> n && n)
    {
        int cnt = 0;
        while (n)
        {
            if (1 == n%2)
            {
                cout << pow(2, cnt) << endl;
                break;
            }
            else
            {
                n /= 2;
                cnt++;
            }
        }
    }
    return 0;
}
时间: 2025-01-08 12:31:31

HDOJ 1196 Lowest Bit的相关文章

Hdoj 1196 Lowest Bit 【&amp;】

Lowest Bit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9273 Accepted Submission(s): 6824 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. For examp

HDU 1196 Lowest Bit (数位)

Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8166    Accepted Submission(s): 5998 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. For

HDOJ 2028 Lowest Common Multiple Plus

Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33702    Accepted Submission(s): 13766 Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Ou

杭电 HDU 1196 Lowest Bit

Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9052    Accepted Submission(s): 6656 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. For

(HDU)1196 -- Lowest Bit(最低位)

题目链接:http://vjudge.net/problem/HDU-1196 二进制最低位可以用位运算,也可以模拟这个步骤. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <algorithm> 5 6 using namespace std; 7 8 int main() 9 { 10 int A,t; 11 while(scanf("%d&quo

hdu 1196 Lowest Bit

#include<stdio.h> int main() { int i,n,a[10000],sum,j; while(~scanf("%d",&n)&&n) { sum=1; for(i=0;;i++) { a[i]=n%2; n=n/2; if(a[i]) break; } for(j=1;j<=i;j++) sum=sum*2; printf("%d\n",sum); } return 0; }

Lowest Bit------HDOJ杭电1196(想法很重要)

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:

【HDOJ】4605 Magic Ball Game

思路1:树状数组+离线处理,对所有的w离散化处理,边dfs边使用树状数组更新左右w的情况.思路2:主席树,边bfs边建树.结点信息存储cnt,然后在线查询.树状数组. 1 /* 4605 */ 2 #include <iostream> 3 #include <sstream> 4 #include <string> 5 #include <map> 6 #include <queue> 7 #include <set> 8 #inc

杭电 1196

Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7776    Accepted Submission(s): 5715 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A. For