uva 11636

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
    int arry[31] = {1};
    int now = 1;
    for(int i = 1; i <= 30; ++i)
    {
        now *= 2;
        arry[i] = now;
        //printf("%d\t", arry[i]);
    }
    int t, casee = 1;
    //while(scanf("%d", &t) != EOF && (t > 0))
    while(scanf("%d", &t) != EOF && (t > 0))
    {
        for(int i = 1; i <= 30; ++i)
        {
            if(t == 1)
            {
                printf("Case %d: %d\n", casee++, 0);
                break;
            }
            else if(t <= arry[i] && t > arry[i-1])
            {
                printf("Case %d: %d\n", casee++, i);
            }
        }
    }
}

Hello World!
Input: Standard Input

Output: Standard Output

When you first made the computer to print the sentence “Hello World!”, you felt so happy, not knowing how complex and interesting the world of programming and algorithm will turn out to be. Then you did not know anything about loops, so to print 7 lines of “Hello World!”, you just had to copy and paste some lines. If you were intelligent enough, you could make a code that prints “Hello World!” 7 times, using just 3 paste commands. Note that we are not interested about the number of copy commands required. A simple program that prints “Hello World!” is shown in Figure 1. By copying the single print statement and pasting it we get a program that prints two “Hello World!” lines. Then copying these two print statements and pasting them, we get a program that prints four “Hello World!” lines. Then copying three of these four statements and pasting them we can get a program that prints seven “Hello World!” lines (Figure 4). So three pastes commands are needed in total and Of course you are not allowed to delete any line after pasting. Given the number of “Hello World!” lines you need to print, you will have to find out the minimum number of pastes required to make that program from the origin program shown in Figure 1.

       

Figure 1


Figure 2


Figure3


Figure 4

Input

The input file can contain up to 2000 lines of inputs. Each line contains an integer N (0<N<10001) that denotes the number of “Hello World!” lines are required to be printed.

Input is terminated by a line containing a negative integer.

Output

For each line of input except the last one, produce one line of output of the form “Case X: Y” where X is the serial of output and Y denotes the minimum number of paste commands required to make a program that prints N lines of “Hello World!”.

 

 

Sample Input                             Output for Sample Input


2

10

-1


Case 1: 1

Case 2: 4

时间: 2024-08-27 02:35:23

uva 11636的相关文章

UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

课程好紧啊,只能刷点水题了,几乎都是贪心. UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); }

uva 11636 Hello World!(找规律)

uva 11636 Hello World! When you first madethe computer to print the sentence "Hello World!", you felt so happy, not knowinghow complex and interesting the world of programming and algorithmwill turn out to be. Then you did not know anything abou

UVa 11636 你好 世界!(贪心)

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 in

UVa 11636 (注意读题) Hello World!

这道题巨坑啊,样例中以-1结束输入的,所以我就天真的以为测试数据也是以-1结束输入的 其实人家原文中说: Input is terminated by a line containing a negative integer. 是以负数结束输入,囧rz! 我这种英语渣渣,怎么可能注意到这种错误 我还以为是算法的问题,就写了两份代码 1 //#define LOCAL 2 #include <cstdio> 3 4 int a[20000]; 5 6 int main(void) 7 { 8 #

大白书

UVA 11292 (简单贪心) 题意: n条恶龙,m个勇士,用勇士来杀恶龙.一个勇士只能杀一个恶龙.而且勇士只能杀直径不超过自己能力值的恶龙.每个勇士需要支付能力值一样的金币.问杀掉所有恶龙需要的最少金币. 思路: 贪心,均从小到大排序.为每一条龙找一个恰好能杀他的骑士.简单贪心. UVA 11729 (经典贪心问题) 题意: n个任务,需要交代B分钟,执行J分钟,让你合理选择交代任务的次序,求得n个任务完成的最小总时长. 思路: 经典贪心,通过比较俩俩的关系,得到整个序列的贪心排序方法.这个

cumt周练题解

cumt2017春季--周练(一) A.CodeForces - 785A 1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 cin >> n; 7 map<string, int>ma; 8 ma["Tetrahedron"] = 4; 9 ma["Cube"] = 6; 10 ma["Octahedron&quo

大白书第一章

UVA 11292 The Dragon of Loowater(简单贪心) 题意: n条恶龙,m个勇士,用勇士来杀恶龙.一个勇士只能杀一个恶龙.而且勇士只能杀直径不超过自己能力值的恶龙.每个勇士需要支付能力值一样的金币.问杀掉所有恶龙需要的最少金币. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 20000 + 5; 4 int n, m; 5 int night[maxn], dragon[maxn

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te