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 about loops, soto print 7 lines of “Hello World!”, you just
had to copy and pastesome lines. If you were intelligent enough, you could make a codethat prints “Hello World!” 7 times, using just 3 paste commands.Note that we are not interested about the number of copy commandsrequired. A simple program that prints “Hello
World!” is shown inFigure 1. By copying the single print statement and pasting it weget a program that prints two “Hello World!” lines. Then copyingthese two print statements and pasting them, we get a program thatprints four “Hello World!” lines. Then copying
three of these fourstatements and pasting them we can get a program that prints seven“Hello World!” lines (Figure 4). So three pastes commands areneeded in total and Of course you are not allowed to delete anyline after pasting. Given the number of “Hello
World!” lines youneed to print, you will have to find out the minimum number ofpastes required to make that program from the origin program shownin Figure 1.






Figure 1


Figure 2


Figure3


Figure 4

Input

The input file cancontain up to 2000 lines of inputs. Each line contains an integer N(0

Input is terminatedby a line containing a negative integer.

Output

For each line ofinput 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 theminimum number of paste commands required to make a program thatprints N lines of “Hello
World!”.

 

SampleInput                            Output
for Sample Input


2

10

-1


Case 1: 1

Case 2: 4

题目大意:简单题。

解题思路:推数据。

#include<stdio.h>
int main() {
	int n, Case = 1;
	while (scanf("%d", &n) == 1, n >= 0) {
		int temp = 1, ans = 0;
		while (temp < n) {
			temp *= 2;
			ans++;
		}
		printf("Case %d: %d\n", Case++, ans);
	}
	return 0;
}
时间: 2024-10-27 11:21:40

uva 11636 Hello World!(找规律)的相关文章

UVa 1620 Lazy Susan (找规律)

题意:给 n 个数,每次可以把4个连续的数字翻转,问你能不能形成1-n的环状排列. 析:找一下奇偶性,写几个数试试,就会找到规律. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <qu

UVa 12627 (递归 计数 找规律) Erratic Expansion

直接说几个比较明显的规律吧. k个小时以后,红气球的个数为3k. 单独观察一行: 令f(r, k)为k个小时后第r行红气球的个数. 如果r为奇数,f(r, k) = f((r+1)/2, k-1) * 2 如果r为偶数,f(r, k) = f(r/2, k-1) 令g(r, k)为k个小时后前r行红气球的个数. 如果r为偶数,g(r, k) = g(r/2, k-1) * 3; 如果r为奇数,g(r, k) = g(r-1, k) + f(r, k); 因此f和g都可以用递归求解. 1 #inc

UVA 1363 Joseph&#39;s Problem 找规律+推导 给定n,k;求k%[1,n]的和。

/** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想法才明白. 我一开始往素数筛那种类似做法想. 想k%[1,n]的结果会有很多重复的,来想办法优化. 但没走通. 果然要往深处想. 通过观察数据发现有等差数列.直接观察很难确定具体规律:此处应该想到用式子往这个方向推导试一试. lrj想法: 设:p = k/i; 则:k%i = k-i*p; 容易想到

(白书训练计划)UVa 12627 Erratic Expansion(递归+找规律)

题目地址:UVa 12627 这题是先找规律,规律在于对于第k个小时的来说,总是可以分成右下角全是蓝色气球,右上角,左下角与左上角三个一模一样的k-1个小时的气球.这样的话,规律就很清晰了,然后用递归做比较方便... 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <ma

UVA - 11384 - Help is needed for Dexter (找规律!!)

UVA - 11384 Help is needed for Dexter Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem H Help is needed for Dexter Time Limit: 3 Second Dexter is tired of Dee Dee. So he decided to keep Dee Dee b

递推+高精度+找规律 UVA 10254 The Priest Mathematician

题目传送门 1 /* 2 题意:汉诺塔问题变形,多了第四个盘子可以放前k个塔,然后n-k个是经典的汉诺塔问题,问最少操作次数 3 递推+高精度+找规律:f[k]表示前k放在第四个盘子,g[n-k]表示经典三个盘子,2 ^ (n - k) - 1 4 所以f[n] = min (f[k] * 2 + g[n-k]),n<=10000,所要要用高精度,另外打表能看出规律 5 */ 6 /************************************************ 7 * Auth

【UVA】11040 - Add bricks in the wall(找规律)

一道找规律的题,可以看出,大的三角形可以划分成好多个三层的三角形: [x] [a][x-a] [y] [    ][z] 这里面xyz都已知,所以可以求出a = (x + y - z ) /2 14043615 11040 Add bricks in the wall Accepted C++ 0.019 2014-08-15 06:02:50 #include<cstdio> #include<cstring> #include<iostream> #include&

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

UVA 11774 - Doom&#39;s Day(规律)

UVA 11774 - Doom's Day 题目链接 题意:给定一个3^n*3^m的矩阵,要求每次按行优先取出,按列优先放回,问几次能回复原状 思路:没想到怎么推理,找规律答案是(n + m) / gcd(n, m),在topcoder上看到一个证明,如下: We can associate at each cell a base 3-number, the log3(R) most significant digits is the index of the row of the cell