此系列刚开始两天就被十一假期打断了,去山西玩了几天,今天刚回来,为了弥补一下心里的貌似隐隐作痛的愧疚感,挑了个简单的练练手,权当给自己补上一刀。
今天的题目是Hangover,如下:
Description
How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the table.) With two cards you can make
the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2+1/3=5/6
card lengths. In general you can makencards overhang by 1/2+1/3+1/4+...+1/(n+1)
card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n+1).
This is illustrated in the figure below.
Input
The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number
c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.
Output
For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples.
Sample Input
1.00
3.71
0.04
5.19
0.00
Sample Output
3 card(s)
61 card(s)
1 card(s)
273 card(s)
代码如下:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Hangover {
public static void main(String args[]){
List<Float> list = new ArrayList<Float>();
Scanner scanner = new Scanner(System.in);
int all = scanner.nextInt();
while(all > 0){
list.add(scanner.nextFloat());
all --;
}
for(int i = 0; i < list.size(); i ++){
float f = list.get(i);
int count = 1;
float j=2,sum=0;
for(; sum + (1/j) < f; j ++){
count ++;
sum = sum+ (1/j);
}
System.out.println(count + " card(s)");
}
}
}
输入输出如下:
4 1.00 3.71 0.04 5.19
3 card(s)
61 card(s)
1 card(s)
273 card(s)
由于输入的时候弄了半天没想出合适的用0.00结尾的方法,就用了开头先输入一个整数,表示后面要输入的整数个数,然后依次输入的方法,
相信你能看懂。
作者:jason0539
微博:http://weibo.com/2553717707
博客:http://blog.csdn.net/jason0539(转载请说明出处)
分享到:
相关推荐
Hangover
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44187 Accepted: 20574 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a...
北大POJ1003-Hangover 解题报告+AC代码
这是Hangover,这是由StefanDösinger和AndréHentschel发起的一个项目,用于在aarch64 / ppc64le / x86_64 Wine上运行x86_64 / x86_32 Windows应用程序。 1)运作方式 在主机上,只有64位模式下有一个Wine,而对于...
为了解决短波通信中语音检测的问题,针对短波语音信噪比低,噪声复杂的特点,对幅度谱熵算法进行了修正,选取功率谱熵作为VAD特征,加入谱熵平滑和hangover设计,研究了基于功率谱熵的语音端点检测算法。实验证明,...
宿醉 消息来源 先决条件 建造 npm install npm run build_resources npm run build
1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有...
Hangover是Google的即时通讯服务Hangouts的第一个本机Mac客户端。 目前,它实质上是 ( 的本机Swift端口,这是第一个第三方Google Hangouts客户端。 从长远来看,Hangover打算成为Google忘记为Mac OS X制作的Google ...
然后,它会根据我们的算法为您提供第二天早上宿醉的可能性。 您可以将预测的宿醉程度与您早上的感觉进行比较。 只要让我们知道它是否比我们预测的更糟或更好,我们的算法将根据您的实际经验进行调整。 您使用该应用...
保持固化 一个借助[TheCocktailDB]( )查看来自世界各地的饮料和鸡尾酒食谱的React应用程序。 特征 搜索和查看来自世界各地的饮料和鸡尾酒的食谱。 在彩色模式和深色模式之间切换。 开发人员说明 ...
依赖关系 节点 Ruby 入门 bundle install npm install bower install cd client bundle install npm install bower install 见 部署 ./script/deploy
1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有...
内容 程序设计课程 算法 + 数据结构 = 程序 程序设计计算机科学与技术的核心全文共42页,当前为第2页。 程序设计课程 课程性质 科学?技术?工程? 技术课程 课程目的 编写程序解决问题 教学方式 课堂讲授 / 理论...
BP神经网络的数据分类-语音特征信号分类,主要根据BP神经网络理论,在MATLAB软件中实现基于BP神经网络的语言特征信号的分类算法。包括数据选择和归一化,BP神经网络构建、BP神经网络训练以及BP神经网络分类。
Lust,BooBoo,哀伤,maf,唯一の小排,Hangover,ramsesses,Tails,箭魚,★顺其自然★,形单影只,Uriel,树林,X逍遥游,Gnik,格兰蒂恩,VancoMYcin,Kai Ge,Bane,楼のFate,康笑风,子小光军,Demise|狼,...
数组方法:闲来无事,简单总结一下前端开发中常用的数组方法!不足之处,欢迎扔砖!
附带数据库,所有类名严格按照规范,代码工整,清晰易懂
SYN6288模块 PCB板封装.PCB