[POJ] #1003# Hangover : 浮点数运算
一. 题目
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 116593 | Accepted: 56886 |
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
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
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)
Source
- 按照固定的累加方式:从高层到低层,相对于其相邻下层可以伸出的长度为(1/2),(1/3),...,(1/n)
- 给定一个指定长度 S,问最少需要累加多上块板,使其相对于桌面的伸出长度大于或等于 S
三. 分析
- 算法核心: 此题比较简单,无需考虑任何算法
- 实现细节: 简单的浮点数累加运算即可
四. 题解
#include <stdio.h> int main()
{
int i;
float length, sum; while () {
sum = ;
scanf("%f\n", &length);
if (!length) break; for (i = ; ; i++) {
sum += ( / (float)i); if (sum >= length) {
printf("%d card(s)\n", i - );
break;
}
}
} return ;
}
[POJ] #1003# Hangover : 浮点数运算的更多相关文章
- POJ.1003 Hangover ( 水 )
POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...
- OpenJudge / Poj 1003 Hangover
链接地址: Poj:http://poj.org/problem?id=1003 OpenJudge:http://bailian.openjudge.cn/practice/1003 题目: Han ...
- [POJ 1003] Hangover C++解题
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95164 Accepted: 46128 De ...
- poj 1003:Hangover(水题,数学模拟)
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 99450 Accepted: 48213 Descri ...
- 快速切题 poj 1003 hangover 数学观察 难度:0
Hangover Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 103896 Accepted: 50542 Descr ...
- poj 1003 Hangover
#include <iostream> using namespace std; int main() { double len; while(cin >> len & ...
- [POJ] #1004# Financial Management : 浮点数运算
一. 题目 Financial Management Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 173910 Acc ...
- js,java,浮点数运算错误及应对方法
js,java浮点数运算错误及应对方法 一,浮点数为什么会有运算错误 IEEE 754 标准规定了计算机程序设计环境中的二进制和十进制的浮点数自述的交换.算术格式以及方法. 现有存储介质都是2进制.2 ...
- 深入理解计算机系统(2.8)---浮点数的舍入,Java中的舍入例子以及浮点数运算(重要)
前言 上一章我们简单介绍了IEEE浮点标准,本次我们主要讲解一下浮点运算舍入的问题,以及简单的介绍浮点数的运算. 之前我们已经提到过,有很多小数是二进制浮点数无法准确表示的,因此就难免会遇到舍入的问题 ...
随机推荐
- hdu - 1240 Nightmare && hdu - 1253 胜利大逃亡(bfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1240 开始没仔细看题,看懂了发现就是一个裸的bfs,注意坐标是三维的,然后每次可以扩展出6个方向. 第一维代表在 ...
- 在cmd中登录ftp服务器
http://jingyan.baidu.com/article/0bc808fc8778ee1bd485b93b.html C:\Users\Administrator>ftpftp> ...
- 《OD学oozie》20160813
一.日志收集项目案例 1. oozie中依赖jar包 在工作目录下创建lib目录,上传依赖包的lib目录下 2. 作业 将日志收集与处理项目案例使用oozie的workflow执行 3. coordi ...
- 在服务器端保存ViewState
1.比较 Asp.net 的一个强大的功能就是ViewState, 但是这也成为很多人诟病的地方,我们先来看一个实例 ViewState其中一个特性就是保存页面的状态,下面我们看一个很简单的登录页面 ...
- 标准模板库(STL)学习探究之stack
标准模板库(STL)学习探究之stack queue priority_queue list map/multimap dequeue string
- 【MySQL】ERROR 1045 (28000): Access denied for user的解决方法
去官网下载压缩版的MySQL Server,解压配置path环境变量后.然后克隆my-default.ini创建my.ini文件,在文件中[mysqld]下面配置basedir和datadir bas ...
- C#配置系统未能初始化
如果配置文件中包含 configSections 元素,则 configSections 元素必须是 configuration 元素的第一个子元素.",将appSettings放到conf ...
- Drawable和Bitmap的区别
Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...
- BZOJ 3406 乳草的入侵
BFS. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&g ...
- mysqldump备份数据库时排除某些库
说明:使用mysqldump –all-databases会导出所有库.但如果做主从,从主库dump出数据时,我们是不需要也不想要information_schema 和 mysql 库的.数据库少的 ...