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

UVA11636- Hello World!

时间:2014-08-06 23:07:12      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:style   color   使用   os   io   amp   size   ios   

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


UVA11636- Hello World!,布布扣,bubuko.com

UVA11636- Hello World!

标签:style   color   使用   os   io   amp   size   ios   

原文地址:http://blog.csdn.net/u011345461/article/details/38406437

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