zoukankan      html  css  js  c++  java
  • BZOJ 1192 鬼谷子的钱袋 数论

    1192:鬼谷子的钱袋

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 1926  Solved: 1417

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=1192

    Description

    鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政。有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商 行)将要举行一场拍卖会,其中有一件宝物引起了他极大的兴趣,那就是无字天书。但是,他的行程安排得很满,他他已经买好了去邯郸的长途马车标,不巧的是出 发时间是在拍卖会快要结束的时候。于是,他决定事先做好准备,将自己的金币数好并用一个个的小钱袋装好,以便在他现有金币的支付能力下,任何数目的金币他 都能用这些封闭好的小钱的组合来付账。鬼谷子也是一个非常节俭的人,他想方设法使自己在满足上述要求的前提下,所用的钱袋数最少,并且不有两个钱袋装有相 同的大于1的金币数。假设他有m个金币,你能猜到他会用多少个钱袋,并且每个钱袋装多少个金币吗?

    Input

    包含一个整数,表示鬼谷子现有的总的金币数目m。其中,1≤m ≤1000000000。

    Output

    只有一个整数h,表示所用钱袋个数

    Sample Input

    3

    Sample Output

    2

    HINT

    题解:

    这是一道数论题

    我们可以简单分析一下,每一个数,都可以由二进制数表示~

    这就类似于二进制的加法操作一样,01+10=100

    反正就这样乱分析一下,我们就知道最后答案就是log2(n)+1

    代码:

    //qscqesze
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 200001
    #define mod 10007
    #define eps 1e-9
    const int inf=0x7fffffff;   //无限大
    /*
    
    */
    //**************************************************************************************
    inline int read()
    {
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int main()
    {
        int n=read();
        int ans=0;
        while(n!=0)
        {
            ans++;
            n/=2;
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    自定义可下拉刷新列表
    在listview里面的checkbox被选中或取消
    [转]Android中音乐文件的信息详解【安卓源码解析二】
    service 和broadcastreceiver的简略小结
    闹铃
    hdu 2112赤裸裸的最短路
    hdu 2177错题,很水的测试数据
    hdu 2184模拟
    hdu1150最小点集覆盖
    hdu 3746KMP的应用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4363641.html
Copyright © 2011-2022 走看看