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
Output
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)\n", i); 31 } 32 return 0; 33 }