bzoj 1192: [HNOI2006]鬼谷子的钱袋
1192: [HNOI2006]鬼谷子的钱袋
Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3192 Solved: 2313 [Submit][Status][Discuss]
Description
鬼谷子非常聪明,正因为这样,他非常繁忙,经常有各诸侯车的特派员前来向他咨询时政。有一天,他在咸阳游历的时候,朋友告诉他在咸阳最大的拍卖行(聚宝商行)将要举行一场拍卖会,其中有一件宝物引起了他极大的兴趣,那就是无字天书。但是,他的行程安排得很满,他他已经买好了去邯郸的长途马车标,不巧的是出发时间是在拍卖会快要结束的时候。于是,他决定事先做好准备,将自己的金币数好并用一个个的小钱袋装好,以便在他现有金币的支付能力下,任何数目的金币他都能用这些封闭好的小钱的组合来付账。鬼谷子也是一个非常节俭的人,他想方设法使自己在满足上述要求的前提下,所用的钱袋数最少,并且不有两个钱袋装有相同的大于1的金币数。假设他有m个金币,你能猜到他会用多少个钱袋,并且每个钱袋装多少个金币吗?
Input
包含一个整数,表示鬼谷子现有的总的金币数目m。其中,1≤m ≤1000000000。
Output
只有一个整数h,表示所用钱袋个数
Sample Input
3
Sample Output
2
思路:转化成二进制表示….还是蛮容易想到的吧。
1/* ***********************************************
2Author :111qqz
3Created Time :2016年11月28日 星期一 15时31分21秒
4File Name :code/bzoj/1192.cpp
5************************************************ */
6
7#include <cstdio>
8#include <cstring>
9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33int two[60];
34int main()
35{
36 #ifndef ONLINE_JUDGE
37// freopen("code/in.txt","r",stdin);
38 #endif
39 int m;
40 cin>>m;
41 int cnt = 0 ;
42 while (m)
43 {
44 m = m >> 1;
45 cnt++;
46 }
47 cout<<cnt<<endl;
48
49
50 #ifndef ONLINE_JUDGE
51 fclose(stdin);
52 #endif
53 return 0;
54}