HDUOJ--1058HangOver

HangOver

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7884    Accepted Submission(s): 3233

Problem 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.

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.

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

http://acm.hdu.edu.cn/showproblem.php?pid=1056

代码:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     double a,sum;
 5     int i;
 6     while(scanf("%lf",&a),a)
 7     {
 8         sum=0.0;
 9      for(i=2;i<=277;i++)
10      {
11          sum+=1.0/i;
12        if(sum-a>=0) break;
13      }
14      printf("%d card(s)\n",i-1);
15     }
16     return 0;
17 }

数学题...就是搞不清要精确到哪一点..这样的,虽然 及其简单。。。但是往往AC率不高!!

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏ml

hdu 4009 Transfer water(最小型树图)

Transfer water Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/657...

37490
来自专栏xingoo, 一个梦想做发明家的程序员

HDOJ 1012

水题天天有,今天特别多....嘿嘿 u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memor...

23170
来自专栏ml

HDUOJ 1099——Lottery

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

37070
来自专栏ml

HDUOJ----2647Reward

Reward Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja...

36580
来自专栏ml

HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)

A simple stone game                                                             ...

29050
来自专栏ml

HDUOJ--1159Common Subsequence

Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536...

26970
来自专栏ml

hdu---(5038)Grade(胡搞)

Grade Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (J...

33190
来自专栏算法修养

HDU 1103 Flo's Restaurant(模拟+优先队列)

Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/...

28860
来自专栏小樱的经验随笔

HDU 1004 Let the Balloon Rise【STL<map>】

Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 655...

30240
来自专栏ml

HDUOJ---(4708)Rotation Lock Puzzle

Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327...

24940

扫码关注云+社区

领取腾讯云代金券