poj 1003 Hangover

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)
这个题就是一个大水题!!!!翻译过来就是1/2+1/3+1/4+……+1/(n+1)什么时候>c,
#include<cstdio>
int main()
{
    float c;
    while(scanf("%f",&c)==1&&c!=0.00)
    {
        float s=0;//不是int
        int sum=0;
        float t=2;//这个也不能是int
        while(s<c)
        {
            s=s+1/t;
            t++;
            sum++;
        }
        printf("%d card(s)\n",sum);
    }
    return 0;
}
一开始我就是这么写的,但是输入后没有输出,我就看了一下其他人写的,但是是前天晚上看的,我们昨天休息,所以也没看,今天早上到了之后看的,就想着先自己改改,但是还没改对,我又想看别人写的代码了,
但是我又看了一下题,再 改了一下,我就没抱希望自己会对,但是运行没错误,就输入数据,这个我也没抱希望,结果!!!第一个数据对了,激动!!!就继续测试第二个,第三个,都对!!!然后就提交,通过!!!
然后反思了一下,感觉自己太依赖别人的代码了,一不会就上网找别人的代码,尤其是改不对的时候,我就认为自己笨,肯定做不出来,不会就没办法,然后就给自己找借口什么的,哎,以后呢,要相信自己啦
但是看别人的代码跟我的不一样,我的就是一看题就那么写,跟英语翻译一样,一个字对应一个词,而别人不是这么写的,他们会变通一下,他用的就是把每个相加后都存起来,然后用输入的数根存好的数比较,
这样我感觉对于输入比较大的数据来说会好一点,我这个就是一个输入就循环一次,数太多就不好弄
posted @ 2016-07-25 08:42  小小姐  阅读(96)  评论(0编辑  收藏  举报