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

POJ 1003 && HDU 1056 HangOver(水~)

2015-08-23 14:07 525 查看
Description

给出一个浮点数c,求出使得不等式 1/2 + 1/3 + … + 1/(n+1) >= c 成立的最小n

Input

多组用例,每组用例一个浮点数,以0.00结束输入

Output

对于每组用例,输出满足条件的最小n值

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)

Solution

水题

Code

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