码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 11636 你好 世界!(贪心)

时间:2017-03-08 00:42:26      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:log   get   blank   题意   algorithm   logs   const   out   net   

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 }

 

UVa 11636 你好 世界!(贪心)

标签:log   get   blank   题意   algorithm   logs   const   out   net   

原文地址:http://www.cnblogs.com/zyb993963526/p/6517346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!