POJ 1003 hangover&&nyoj 156 Hangover "Math Problem"

Source: Internet
Author: User

Calculate 1+1/2+1/3+++1/n


Hangover
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 104558 Accepted: 50926

Description

How far can I make a stack of cards overhang a table? If you had one card, you can create a maximum overhang of half a card length. (We ' re assuming that the cards must is perpendicular to the table.) With both cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the TA Ble by a third of a card length, for a total maximum overhang of a + 1/3 = 5/6 card lengths. In general you can make n cards overhang by + 1/3 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by, the second overhangs Tha third by 1/3, the third overhangs the fourth by the quarter, etc, and the bottom card overhangs the table by 1/(n + 1). This was illustrated in the 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 Put. Each test case was a single line containing a positive floating-point number C whose value was at least 0.01 and at the most 5.2 0; C'll contain exactly three digits.

Output

For each test case, the output the minimum number of cards necessary to achieve a overhang of at least C card lengths. Use the exact output format shown in the examples.

Sample Input

1.003.710.045.190.00

Sample Output

3 Card (s) 1 card (s) 273 card (s)

Source

Mid-Central USA 2001


#include <stdio.h>int main () {double S,sum;int i,t;while (scanf ("%lf", &s), s) {for (i=2,sum=0;; i++) {sum+=1.0/i;if (sum>=s) {t=i;break;}} printf ("%d card (s) \ n", t-1);} return 0;}



POJ 1003 hangover&&nyoj 156 Hangover "Math Problem"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.