UVA11636- Hello World!

题意:使用最小的复制/黏贴次数,使得语句的条数恰好为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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值