题意:使用最小的复制/黏贴次数,使得语句的条数恰好为n
思路:贪心思想,因为复制是所有条数翻倍,所以每次都取最大的条数*2
PS:天真的认为是n = -1时退出,所以WA了好几次。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
int n, t = 1;
while (scanf("%d", &n) != EOF) {
if (n < 1)
break;
int cnt = 1, num = 0;
while (cnt < n) {
num++;
cnt *= 2;
}
printf("Case %d: %d\n", t++, num);
}
return 0;
}