您的位置:首页 > 编程语言 > Go语言

poj 1003 Hangover

2013-07-29 11:51 363 查看
Hangover

Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 84652
Accepted: 40731
Description
How far can you makea stack of cards overhang a table? If you have one card, you can create amaximum overhang of half a card length. (We're assuming that the cards must beperpendicular to the table.) With two cards you can make the top card
overhangthe bottom one by half a card length, and the bottom one overhang the table bya third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 cardlengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1)
card lengths, where the top card overhangsthe second by 1/2, the second overhangs tha third by 1/3, the third overhangsthe fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

悬在桌边的卡片,你能给摞多远?如果你有一长卡片,你可以最多用这个卡片的一半来覆盖这个桌子(我们假设这卡片必须与桌面垂直),对于邻近的两张卡片,你可以把一张覆盖到另一张上面,然后最底下的那一张覆盖桌子的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)。下面的图像举了一个实例。
Input
The inputconsists of one or more test cases, followed by a line containing the number0.00 that signals the end of the input. Each test case is a single linecontaining a positive floating-point number c whose value is at least 0.01 andat most
5.20; c will contain exactly three digits.
Output
For eachtest case, output the minimum number of cards necessary to achieve an overhangof 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
Mid-Central USA 2001

Hangover

Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 84652
Accepted: 40731
Description
悬在桌边的卡片,你能给摞多远?如果你有一长卡片,你可以最多用这个卡片的一半来覆盖这个桌子(我们假设这卡片必须与桌面垂直),对于邻近的两张卡片,你可以把一张覆盖到另一张上面,然后最底下的那一张覆盖桌子的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)。下面的图像举了一个实例。

Input
输入包含一组或者多组数据,0.00表示输入结束。每一组数据都是一行正实数c,c的范围在0.01和5.20之间;c由3个数字组成
Output
对于每一组数据,输出覆盖出来c的长度所需要的最少的卡片。就采用给出的输出例子的那种格式
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
Mid-Central USA 2001

额,很水的题,就是用1/2+…1/n刚好比输入的数小就行,然后俺才知道如果输入用%llf。。。会t……..

#include<stdio.h>
#include<string.h>
#include<math.h>

void input(void);

int main(void){
freopen("in.txt","r", stdin);
input();
return 0;
}

void input(void){
double f, s;
int i;
while(scanf("%lf", &f) && (f > 0)){
for (s = 0, i = 2;s < f;s += 1.0/i,i++);
printf("%d card(s)\n", i-2);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: