您的位置:首页 > 其它

UVa 11636 你好 世界!(贪心)

2017-03-07 23:02 169 查看
https://vjudge.net/problem/UVA-11636

题意:

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

思路:

贪心水题。

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

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

const int maxn = 50 + 5;

int n;

int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\txt.txt", "r", stdin);
int kase = 0;
while (cin >> n && n >=0)
{
int num = 1;
int cnt = 0;
while (true)
{
if (num >= n)
break;
num *= 2;
cnt++;
}
cout << "Case " << ++kase << ": " << cnt << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: