一. 题目

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

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)

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 : 浮点数运算的更多相关文章

  1. POJ.1003 Hangover ( 水 )

    POJ.1003 Hangover ( 水 ) 代码总览 #include <cstdio> #include <cstring> #include <algorithm ...

  2. OpenJudge / Poj 1003 Hangover

    链接地址: Poj:http://poj.org/problem?id=1003 OpenJudge:http://bailian.openjudge.cn/practice/1003 题目: Han ...

  3. [POJ 1003] Hangover C++解题

        Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95164   Accepted: 46128 De ...

  4. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

  5. 快速切题 poj 1003 hangover 数学观察 难度:0

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 103896   Accepted: 50542 Descr ...

  6. poj 1003 Hangover

    #include <iostream> using namespace std; int main() { double len; while(cin >> len & ...

  7. [POJ] #1004# Financial Management : 浮点数运算

    一. 题目 Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 173910   Acc ...

  8. js,java,浮点数运算错误及应对方法

    js,java浮点数运算错误及应对方法 一,浮点数为什么会有运算错误 IEEE 754 标准规定了计算机程序设计环境中的二进制和十进制的浮点数自述的交换.算术格式以及方法. 现有存储介质都是2进制.2 ...

  9. 深入理解计算机系统(2.8)---浮点数的舍入,Java中的舍入例子以及浮点数运算(重要)

    前言 上一章我们简单介绍了IEEE浮点标准,本次我们主要讲解一下浮点运算舍入的问题,以及简单的介绍浮点数的运算. 之前我们已经提到过,有很多小数是二进制浮点数无法准确表示的,因此就难免会遇到舍入的问题 ...

随机推荐

  1. 每天一个小算法(Heapsort)

    #include "stdio.h" #include "stdlib.h" #define Num 10 Heap(int arr[],int i,int n ...

  2. poj 1182 食物链 (并查集)

    http://poj.org/problem?id=1182 关于并查集 很好的一道题,开始也看了一直没懂.这次是因为<挑战程序设计竞赛>书上有讲解看了几遍终于懂了.是一种很好的思路,跟网 ...

  3. JSON(3)Google解析Json库Gson

    本文参考 : http://www.cnblogs.com/chenlhuaf/archive/2011/05/01/gson_test.html 1.资料 官网: http://groups.goo ...

  4. Oracle中用一个表的数据更新另一个表的数据

    update tbl1 a   set (a.col1, a.col2) = (select b.col1, b.col2                              from tbl2 ...

  5. 手机号段、ip地址归属地大全,最新手机号段归属地,IP地址归属地数据库

    百事通:http://www.114best.com/dh/114.aspx?w=17097232323,联通识别为电信的,1349错 二三四五:http://tools.2345.com/frame ...

  6. jQuery_效果(隐藏和显示)

    一.jQuery hide() 显示和 show()隐藏 通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素: <script type=" ...

  7. Machine Learning for hackers读书笔记_一句很重要的话

    为了培养一个机器学习领域专家那样的直觉,最好的办法就是,对你遇到的每一个机器学习问题,把所有的算法试个遍,直到有一天,你凭直觉就知道某些算法行不通.

  8. ecshop 调用指定分类的推荐,热卖,新品

    未测试 1.includes/lib_goods.php文件.把SQL语句改一下,与category表关联即可 将 $sql = 'SELECT g.goods_id,g.goods_name, g. ...

  9. Android源码分析--CircleImageView 源码详解

    源码地址为 https://github.com/hdodenhof/CircleImageView 实际上就是一个圆形的imageview 的自定义控件.代码写的很优雅,实现效果也很好, 特此分析. ...

  10. devexpress GridControl 行指示列图标绘制

    Row Indicator Panel The row indicator panel represents a region displayed at the left edge of the Vi ...