[恢]hdu 1056
2011-12-26 09:44:26
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1056
题意:问1/2+1/3+1/4...+1/n不超过输入的最大n是多少。
mark:1wa,注意0.5算1。
代码:
# include <stdio.h>
# include <math.h>
double tab[300] ;
int main ()
{
int i ;
double num ;
for (i = 2 ; i <= 280 ; i++)
tab[i] = tab[i-1] + 1.0/i ;
while (~scanf ("%lf", &num) && fabs(num) > 1e-9)
{
for (i = 2 ; ; i++)
if (num <= tab[i]) break ;
printf ("%d card(s)\n", i-1) ;
}
}