UVa 11636 你好 世界!(贪心)

https://vjudge.net/problem/UVA-11636

题意:

经过一次复制,一条语句会变成两条语句,再经过一次变成四条语句...求最少需要复制几次能使条数恰好为n?

 

思路:

贪心水题。

每次以最大复制数复制即可。

 1 #include<iostream> 
 2 #include<algorithm>
 3 #include<string>
 4 using namespace std;
 5 
 6 const int maxn = 50 + 5;
 7 
 8 int n;
 9 
10 int main()
11 {
12     ios::sync_with_stdio(false);
13     //freopen("D:\\txt.txt", "r", stdin);
14     int kase = 0;
15     while (cin >> n && n >=0)
16     {
17         int num = 1;
18         int cnt = 0;
19         while (true)
20         {
21             if (num >= n)
22                 break;
23             num *= 2;
24             cnt++;
25         }
26         cout << "Case " << ++kase << ": " << cnt << endl;
27     }
28 }

 

posted @ 2017-03-07 23:02  Kayden_Cheung  阅读(199)  评论(0编辑  收藏  举报
//目录