NUC1003 Hangover
Hangover
时间限制: 1000ms 内存限制: 65536KB
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 are 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.
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.
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.
1.00 3.71 0.04 5.19 0.00
3 card(s) 61 card(s) 1 card(s) 273 card(s)
问题分析:
这个题与《POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover》完全相同,代码直接拿过来用就AC了。
程序说明:
参见参考链接。
参考链接:POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover
题记:
程序写多了,似曾相识的也就多了。
AC的C++程序如下:
/* POJ1003 UVALive2294 HDU1056 ZOJ1045 Hangover */ #include <iostream>
#include <cstdio> using namespace std; const double one = 1.0; int main()
{ double len, sum, d; int i; while((cin >> len) && len != 0.00) { i = 1; d = 2.0; sum = one / d; while(sum < len) { d += 1.0; sum += (one / d); i++; } cout << i << " card(s)" << endl; } return 0;
}
转载于:https://www.cnblogs.com/tigerisland/p/7563785.html
NUC1003 Hangover相关推荐
- NUC1003 Hangover【数学计算+水题】
Hangover 时间限制: 1000ms 内存限制: 65536KB 问题描述 How far can you make a stack of cards overhang a table? If ...
- HDOJ 1056 HangOver
简单的题目,我的解法采用预处理,然后使用折半查找返回答案. #include<stdio.h> double answer[300]; int len=0; double num; int ...
- POJ 1003 Hangover
POJ 1003 Hangover 水题 //POJ 1003 #include <iostream>using namespace std; float l[1001];int main ...
- POJ1003·Hangover
2019独角兽企业重金招聘Python工程师标准>>> Description How far can you make a stack of cards overhang a ta ...
- (HDU)1056 --HangOver( 悬住)
题目链接:http://vjudge.net/problem/HDU-1056 第一次写的时候TLE了,原因是处理double型计算的时候,丢失了精度,跳不出循环. 在算式第一个数字后加.0就可以了. ...
- [POJ 1003] Hangover C++解题
翻译: 若将一叠卡片放在一张桌子的边缘,你能放多远?如果你有一张卡片,你最远能达到卡片长度的一半.(我们假定卡片都正放在桌 子上.)如果你有两张卡片,你能使最上的一张卡片覆盖下面那张的1/2,底下的那 ...
- Hangover C语言 UVA2294
试图使用离线计算的方法但是失败了,wa到我一脸懵逼,因此对每一个数据,我从放一张卡开始计算长度,直到长度大于给出数为止. 1 #include <stdio.h> 2 #include & ...
- POJ 1003 Hangover 水题
题目看着挺复杂,还配了个看上去就很高大上的图,但是看完题就发现,完完全全是一道水题= =好吧,题意简单说就是有一排数,是1/2,1/2+1/3,1/2+1/3+1/4.......然后给出一个数,问这 ...
- Day 08 周六下午的活动
1.今日话题 Which of the following activities do you prefer the most on a Saturday afternoon: doing exer ...
最新文章
- Spring Boot 面试杀手锏:自动配置原理
- TiDB与gRPC的那点事
- [Windows驱动开发](四)内存管理
- 【计算机系统设计】学习笔记(1)03,04
- Python中出现:AttributeError: module 'numpy' has no attribute 'dtype'问题解决
- Android 实践项目开发二
- 怎样改变java编码风格_如何说服同事修改些代码的风格(JAVA的)。。求指引
- 使用ipmitool命令检测电源模块状态
- vue-cli3 vue.config.js配置
- springboot flink结果输入到hbase_Flink流处理
- 快速突破面试算法之动态规划篇
- VINS_Fusion学习01——官方教程翻译解读
- 在ubuntu中安装DroidCam 让Andorid 安卓手机摄像头成为Linux外部可移动摄像头
- safari html5 自动全屏,javascript – 使用iOS Safari网络浏览器的全屏html5视频
- 小肩膀易语言四期POST+JS
- dell笔记本耳机怎么设置_戴尔电脑插耳机不弹出那个框怎么办_win10插入耳机弹不出对话框的解决方法...
- 开发者的拯救者还是掘墓人?解密低代码开发平台 ZT
- what Data Fabric
- 迅雷下载百度云大小文件(实现极速下载)
- RGB 透明度对应值