poj1003

原创 2016年06月01日 01:03:48

Hangover

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 116836 Accepted: 57009

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
Mid-Central USA 2001
水题。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
    int i;
    double f,s;
    while(scanf("%lf",&f)!=EOF&&f!=0.00){
        s=0.0;
        for ( i = 2; s < f; ++i)
        {
            s+=1.0/i;

        }
        printf("%d card(s)\n", i-2);
    }
    return 0;
}
版权声明:本文为博主原创文章,转载请注明出处。

相关文章推荐

POJ 1003代码

  • 2009-10-02 20:46
  • 895B
  • 下载

POJ1003-Hangover

POJ 1003

//刚接触算法,想在博客上记录下自己的POJ历程(虽然刚开始刷)#include using namespace std; const int size = 300; //快速排序 void Q...

poj 1003 Hangover

  • 2009-06-01 13:29
  • 403B
  • 下载

POJ 1003

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

POJ1003-Hangover(水题)

第一次网上做oj!

hdu 1003/poj 1050 连续子序列最大和经典基础dp

之前不太理解,只记得和为负的就记为0,然后不断扫下去,更新ans 实际上用了 sum[i]-sum[j] ,令ans最小,即找出最大的sun[j](j hdu1003  还要求出起始点和终点 #i...

【思维】poj1003 Max Sum

Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su...

poj 1003 1004 1005水

#include #include #include #include #include #include #include #include #include #include u...
  • yeqm_
  • yeqm_
  • 2015-11-02 16:53
  • 147
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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