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 make n cards 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)
#include <stdio.h>
#include <stdlib.h>
int sticknumber(float length);
int main(int argc, char *argv[])
{
float length;
scanf("%4f", &length);
while (length != 0) {
printf("%d card(s)\n", sticknumber(length));
scanf("%4f", &length);
}
}
int sticknumber(float length)
{
int i = 1;
float sum = 1.0/(i + 1);
while (sum < length) {
sum += 1.0/((++i)+1);
}
return i;
}
分享到:
相关推荐
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代码
1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有...
1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有...
这是Hangover,这是由StefanDösinger和AndréHentschel发起的一个项目,用于在aarch64 / ppc64le / x86_64 Wine上运行x86_64 / x86_32 Windows应用程序。 1)运作方式 在主机上,只有64位模式下有一个Wine,而对于...
Hangover是Google的即时通讯服务Hangouts的第一个本机Mac客户端。 目前,它实质上是 ( 的本机Swift... 目前,Hangover是用Swift 2.0编写的,这意味着您将需要才能编译应用程序。 同样,您会注意到Podfile明显为空。 所
依赖关系 节点 Ruby 入门 bundle install npm install bower install cd client bundle install npm install bower install 见 部署 ./script/deploy
宿醉 消息来源 先决条件 建造 npm install npm run build_resources npm run build
保持固化 一个借助[TheCocktailDB]( )查看来自世界各地的饮料和鸡尾酒食谱的React应用程序。 特征 搜索和查看来自世界各地的饮料和鸡尾酒的食谱。 在彩色模式和深色模式之间切换。 开发人员说明 ...
宿醉预测器 此应用程序允许您在镇上的整个晚上跟踪您的酒精消耗量和饮水量。 然后,它会根据我们的算法为您提供第二天早上宿醉的可能性。 您可以将预测的宿醉程度与您早上的感觉进行比较。 只要让我们知道它是否比...
解析 本题采用了非常简单的"输入—处理—输出"模式: 通过结构为for(i=0; i; i++)的循环输入12个月的收入a[0..11]; 累计总收入sum,计算月平均收入avg; 最后输出avg。 程序设计计算机科学与技术的核心全文共42页...
一名BioWare的工作人员向我们解释:一些看似简单的任务并非简单,比如说提老大去讨债,这之间也会有很多可以做的事,你可以尽量的控制状况,让自己受益。欠债的人可订都不会主动偿还的,有时候状况还会失控,导致...
为了解决短波通信中语音检测的问题,针对短波语音信噪比低,噪声复杂的特点,对幅度谱熵算法进行了修正,选取功率谱熵作为VAD特征,加入谱熵平滑和hangover设计,研究了基于功率谱熵的语音端点检测算法。实验证明,...
数组方法:闲来无事,简单总结一下前端开发中常用的数组方法!不足之处,欢迎扔砖!
BP神经网络的数据分类-语音特征信号分类,主要根据BP神经网络理论,在MATLAB软件中实现基于BP神经网络的语言特征信号的分类算法。包括数据选择和归一化,BP神经网络构建、BP神经网络训练以及BP神经网络分类。
附带数据库,所有类名严格按照规范,代码工整,清晰易懂
SYN6288模块 PCB板封装.PCB