zoukankan      html  css  js  c++  java
  • hdu 2175水题

    /*
     * hdu2175/win.cpp
     * Created on: 2012-8-2
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    typedef unsigned long long I64u;
    I64u powoftwo[64];
    void init() {
        powoftwo[0] = 1;
        for(int i = 1; i < 64; i++) {
            powoftwo[i] = powoftwo[i - 1] * 2;
        }
    }
    
    int work(I64u m) {
        for(int i = 0; i < 64; i++) {
            if(m == powoftwo[i]) {
                return i;
            }
        }
        for(int i = 63; i >= 0; i--) {
            if(m > powoftwo[i]) {
                return -i;
            }
        }
        return 0;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int n;
        I64u m;
        init();
        while(scanf("%d%I64u", &n, &m) == 2) {
            if(m == 0 && n == 0) {
                break;
            }
            int ret = work(m);
            while(ret < 0) {
                m -= powoftwo[-ret];
                ret = work(m);
            }
            printf("%d\n", ret + 1);
        }
        return 0;
    }
  • 相关阅读:
    [Poi2000]病毒
    [Zjoi2015]诸神眷顾的幻想乡
    P1663 山
    P1837 单人纸牌
    P6584 重拳出击
    CF460C Present
    10.5 学习笔记
    多项式学习笔记(一) FFT
    NOIP 2020 游记
    uva 经典习题选做(dp专项)
  • 原文地址:https://www.cnblogs.com/moonbay/p/2619255.html
Copyright © 2011-2022 走看看