zoukankan      html  css  js  c++  java
  • [POJ 1003] Hangover C++解题

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

    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/2 + 1/3 = 5/6 的卡片长度。一般地,如果你有n张卡片,你可以伸出 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) 的卡片长度,也就是最上的一张卡片覆盖第二张1/2,第二张超出第三张1/3,第三张超出第四张1/4,依此类推,最底的一张卡片超出桌面1/(n + 1)。下面有个图形的例子:

      

      现在给定伸出长度C(0.00至5.20之间),输出至少需要多少张卡片。

    解决思路


    这是一道水题,直接按照要求模拟就可以了。

    源码

     1 /*
     2 poj 1000
     3 version:1.0
     4 author:Knight
     5 Email:S.Knight.Work@gmail.com
     6 */
     7 
     8 #include<cstdio>
     9 using namespace std;
    10 int main(void)
    11 {
    12     double c;
    13     int i;
    14     double Overhangs;
    15     while(scanf("%lf", &c) == 1)
    16     {
    17         if (0.0 == c)
    18         {
    19             return 0;
    20         }
    21         Overhangs = 0;
    22         for (i=1; i; i++)
    23         {
    24             Overhangs += 1.0 / (i + 1);
    25             if (Overhangs >= c)
    26             {
    27                 break;
    28             }
    29         }
    30         printf("%d card(s)
    ", i);
    31     }
    32     return 0;
    33 }
     
  • 相关阅读:
    ELM学习
    《进化》从孤胆极客到高效团队
    《人件》《PeopleWare》 【美】Tom DeMarco TimothyLister 著 肖然 张逸 滕云 译
    《进化》从孤胆极客到高效团队---Notes1
    大数据第一部分LInux学习Note1
    C#Windows窗体初学
    C#初学笔记(Windows编程的基本概念)
    C#学习2017-9-26(读取文本文件和读取二进制文件)Notes9
    C#学习2017-9-26Notes8(文件和流,FileStream类)
    C#学习笔记Notes8(接口,接口实现,程序集,命名空间,using)
  • 原文地址:https://www.cnblogs.com/BTMaster/p/3525005.html
Copyright © 2011-2022 走看看