Hangover[POJ1003]
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 121079 | Accepted: 59223 |
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
Output
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 <algorithm>
#include <math.h>
using namespace std;
#define eps 1e-8
int main() {
double a, s;
while (scanf("%lf", &a) != EOF) {
if (a < eps) {
break;
}
s = ;
for (int i = ;; i++) {
s += 1.0 / (double)i;
if (s - a > eps) {
printf("%d card(s)\n", i - );
break;
}
}
}
return ;
}
Hangover[POJ1003]的更多相关文章
- [POJ1003]Hangover
[POJ1003]Hangover 试题描述 How far can you make a stack of cards overhang a table? If you have one card, ...
- POJ1003 – Hangover (基础)
Hangover Description How far can you make a stack of cards overhang a table? If you have one card, ...
- 【POJ1003】Hangover(二分搜索)
直接用库函数二分即可. #include <iostream> #include <cstring> #include <cstdlib> #include < ...
- POJ-1003&1004
这两题比较简单,就不做分析了,描述下题目,就上代码吧. [题目描述] 1003,其实就是求这个方程的最小n:1/2 + 1/3 + 1/4 + ... + 1/(n + 1) >= c: 100 ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- HangOver
HangOver Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Hangover 分类: POJ 2015-06-11 10:34 12人阅读 评论(0) 收藏
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 108765 Accepted: 53009 Descr ...
- HDU1056 HangOver
HangOver Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- [POJ] #1003# Hangover : 浮点数运算
一. 题目 Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 116593 Accepted: 56886 ...
随机推荐
- oracle dataguard (一)
一.什么是data guard及data guard的工作原理 Data Guard 是一个集合,由一个primary数据库(生产数据库)及一个或多个standby数据库(最多9个)组成.组成Data ...
- No space left on device 解决Linux系统磁盘空间满的办法
最近Linux电脑在执行mvn时候总是报错: No space left on device 原因是磁盘空间满了,我马上加了20G的硬盘容量,但是还是报错,上网查了一下,发现了解决方法,我用了其中 ...
- MongoDB csv文件导入导出
1.导出到csv文件: 2.从csv导入: 数据经过csv导出导入,有一个非常隐蔽的问题,编写代码时需要注意: 先导入一条数据: 其中Price是double类型: 然后我把该条记录导出到Demo.c ...
- Struts2拦截器之ExceptionMappingInterceptor(异常映射拦截器)
一.异常拦截器是什么? 异常拦截器的作用是提供一个机会,可以设置在action执行过程中发生异常的时候映射到一个结果字符串而不是直接中断. 将异常整合到业务逻辑中,比如在分层系统的调用中可以从底层抛出 ...
- I2C学习
详细的解释: 读写状态机图
- 菜鸟学Linux命令:nohup命令启动程序
在UNIX/LINUX中,普通进程用&符号放到后台运行,如果启动该程序的控制台logout,则该进程随即终止. 要实现守护进程,一种方法是按守护进程的规则去编程,比较麻烦:另一种方法是仍然用普 ...
- 手机的ROM,RAM是各自存放什么?所谓“运行内存”和“机身内存”究竟有什么区别?
手机的内存分为运行内存(RAM)和非运行内存(也叫机身内存.储存空间.ROM) 1.手机的内存,分为存储内存和运行内存,相当于电脑的硬盘和内存条.2.存储内存分为机身内存和存储卡.3.rom是存储内存 ...
- Shell编程基础教程6--shell函数
6.shell函数 6.1.定义函数 简介: shell允许将一组命令集或语句形成一个可用块,这些块成为shell函数 定义函数的格式 ...
- Window Server 2003(IIS6) 安装.net4.0遇到的问题总结
1.Window server 2003系统原本就装了.net1.0..net2.0 ,安装.net 4.0之前,系统已经发不了一些网站,这个时候,我安装.net 4.0返现程序不能访问了,提示ser ...
- js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码
直接上代码 Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...