zoukankan      html  css  js  c++  java
  • UVa 11636

    题目

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683


    题意

    原来有1个,每次可以任选数量成倍增长,问要操作多少次到n

    思路

    明显,先扩增到最大数位maxDigit,比如10,先扩增到8,然后再选择n - maxDigit扩增即可。因而结果为log2(n)

    代码

    #include <algorithm>
    #include <cassert>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <string>
    #include <tuple>
    #define LOCAL_DEBUG
    using namespace std;
    typedef pair<int, int> MyPair;
    
    int cntDigit(int n) {
        int ans = 0;
        int x = 1;
        while (n > x) {
            ans++;
            x <<= 1;
        }
        return ans;
    }
    
    int main() {
    #ifdef LOCAL_DEBUG
        freopen("C:\Users\Iris\source\repos\ACM\ACM\input.txt", "r", stdin);
        //freopen("C:\Users\Iris\source\repos\ACM\ACM\output.txt", "w", stdout);
    #endif // LOCAL_DEBUG
        int n;
        for (int ti = 1; scanf("%d", &n) == 1 && n > 0; ti++) {
            printf("Case %d: %d
    ", ti, cntDigit(n));
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    [JSOI2015]染色问题
    [ZJOI2016]小星星
    [BZOJ4361]isn
    [BZOJ4043/CERC2014]Vocabulary
    [BZOJ3622]已经没有什么好害怕的了
    [BZOJ2958]序列染色
    [SDOI2013]spring
    [Usaco2012 Nov]Concurrently Balanced Strings
    php常用函数集合
    制作item和category的mvc视图总结
  • 原文地址:https://www.cnblogs.com/xuesu/p/10438617.html
Copyright © 2011-2022 走看看