UVA 11636-Hello World!(水题,猜结论)
UVA11636-Hello World!
Time limit: 1.000 seconds
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.
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
2
10
-1
Sample Output
Case 1: 1
Case 2: 4
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683
题目大意:给定n行,求要复制的次数!
分析:这样题意可能比较难理解,(我英文不太好)我是看样例猜答案的,输入的数很有规律,比如样例1,输入2,输出为1,我就这样想,2/2=1,很有道理,再看样例2,输入10,输出按照前面的想法应该是3才对啊,10/2=5,5/2=2,2/2=1->3,稍微拿脑袋想一想就知道不对了,如果向上取整的话是不是就是正解呢,样例1->(2+1)/2=1,样例2->(10+1)/2=5,(5+1)/2=3,(3+1)/2=2,(2+1)/2=1,刚好就等于4,输入小于0的数进行特判即可,于是我就进行了大胆的猜测题意:输入的数每次进行向上取整,求这个数需要经过多少次才能变成1!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
int p=;
while(scanf("%d",&n)!=EOF)
{
if(n<)
break;
int ans=;
while(n>)
{
ans++;
n=(n+)/;
}
printf("Case %d: %d\n",p++,ans);
}
return ;
}
UVA 11636-Hello World!(水题,猜结论)的更多相关文章
- UVA 11636.Hello World!-水题
Hello World! Time limit: 1.000 seconds When you first made the computer to print the sentence “Hello ...
- UVA.11636 Hello World! (思维题)
UVA.11636 Hello World! (思维题) 题意分析 这题挺水的,还是错了几发. QWQ. 有一个同学打了一行hello world,现在他想打n行hello world,请问最少复制粘 ...
- UVa 1339 Ancient Cipher --- 水题
UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- UVa 1586 Molar mass --- 水题
UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现 ...
- UVa 272 Tex Quotes --- 水题
题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Q ...
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 12342 Tax Calculator (水题,纳税)
今天在uva看到一个水题,分享一下. 题意:制定纳税的总额,有几个要求,如果第一个180000,不纳,下一个300000,纳10%,再一个400000,纳15%,再一个300000,纳20%,以后的纳 ...
随机推荐
- iOS masonry九宫格 单行 多行布局
Masonry是个好东西,在当前尺寸各异的iOS开发适配中发挥着至关重要的作用,由于项目中Masonry布局用的比较多,对于UI布局也有了一些自己的理解,经常会有人问道Masonry布局九宫格要怎么布 ...
- iOS 获取一个不变的UDID
原文:iOS7: 如何获取不变的UDID 如何使用KeyChain保存和获取UDID 本文是iOS7系列文章第一篇文章,主要介绍使用KeyChain保存和获取APP数据,解决iOS7上获取不变UDID ...
- C#基础在using中创建对象
在using中创建的对象的类必须是实现了IDispose接口的类,示例代码如下: static void Main(string[] args) { Method(); Console.WriteLi ...
- bzoj 3932: [CQOI2015]任务查询系统
Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si ...
- MySQL数据库入门(建库和建表)--陈远波
建库.建表 1.建库 (1)SQL语句命令建库: Create database数据库名称 (该方法创建的数据库没有设置编码乱码) 1 2 3 4 5 -- 创建数据库时,设置数据库的编码方式 -- ...
- 添加MD5 密码加密
编辑 /etc/grub/grub.conf 配置文件 password = 123456 password --md5 $5$H.........SS grub-crypt --md5 ...
- package-cleanup
package-cleanup 是一个python开发的命令程序,用来清除本机已安装的.重复的 或孤立的软件包. desktop版的CentOS镜像包含这个工具,而Minimal版的CentOS镜像不 ...
- Java Error : type parameters of <T>T cannot be determined during Maven Install
遇到了一个问题如下: Caused by the combination of generics and autoboxing. 这是由于泛型和自动装箱联合使用引起的. 可以查看以下两个回答: 1 ...
- 让 kibana 后台启动的方案
为了解决启动kibana后关闭shell终端kibana自动关闭的问题,记录2种解决方案,试验后均可行. 假设kibana安装的目录为 /usr/local/kibana/ 方案一: 使用nohup ...
- Xamarin.Android 使用Timer 并更改UI
http://blog.csdn.net/ozhangsan12345/article/details/72653070 第一步:创建timer对象 //创建timer对象 Timer _dispat ...