简单模拟。
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int get(double aim)
{
int i;
double s = 0;
for(i = 1; ; i++)
{
if(s >= aim)
{
return i;
break;
}
s += 1.0/(i+1.0);
}
}
int main()
{
double aim;
while(~scanf("%lf", &aim))
{
if(aim == 0.00) break;
printf("%d card(s)\n", get(aim)-1);
}
return 0;
#include <stdlib.h>
#include <string.h>
using namespace std;
int get(double aim)
{
int i;
double s = 0;
for(i = 1; ; i++)
{
if(s >= aim)
{
return i;
break;
}
s += 1.0/(i+1.0);
}
}
int main()
{
double aim;
while(~scanf("%lf", &aim))
{
if(aim == 0.00) break;
printf("%d card(s)\n", get(aim)-1);
}
return 0;
}