NYOJ 156 Hangover

原创 2013年12月03日 14:12:38

Hangover

时间限制:1000 ms  |  内存限制:65535 KB
难度:1
描述

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.


 

输入
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.003.710.045.190.00
样例输出
3 card(s)61 card(s)1 card(s)273 card(s)
来源
POJ
上传者
iphxer
#include<stdio.h>
int main()
{
    double sum;
    while(~scanf("%lf",&sum),sum)
    {
        double s=0,a=0;
        while(sum>s)
        {
            s+=1/(2+a);
            a++;
        }
        printf("%.lf card(s)\n",a);
    }
    return 0;
}

相关文章推荐

NYOJ 156 Hangover

Hangover 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 How far can you make a stack of cards overhang...

NYOJ题目 离线版

  • 2015年09月08日 19:35
  • 1.76MB
  • 下载

北大OJ 1003Hangover && 1001Exponentiation思路

1003 Hangover AC:#include using namespace std; double getSum(int n) { float dRet = 0.00; int...
  • misol
  • misol
  • 2011年05月17日 20:29
  • 1907

HDU1056 HangOver

HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T...

POJ1003-Hangover(水题)

第一次网上做oj!

E - Hangover(1.4.1)

Description How far can you make a stack of cards overhang a table? If you have one card, you c...

hdoj 1056 HangOver

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1056 How far can you make a stack of cards overhan...

北大ACM 1003 Hangover

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 91219   Acce...

POJ1003---Hangover

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 93700   Accepted: 45356 ...

ZOJ P1045 HDOJ P1056 HangOver

HangOver Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total...
  • kdwycz
  • kdwycz
  • 2012年12月04日 12:08
  • 271
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:NYOJ 156 Hangover
举报原因:
原因补充:

(最多只允许输入30个字)