POJ1003
在北大搞学科夏令营的机试题,直接枚举就好,当年脑抽想了十分钟
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const double eps=0.001;
int main(){
for (; ; ){
double goal,test=0;scanf("%lf", &goal);
if (goal<=eps) break;
for (int i=2; ; ++i){
test+=double(1)/i;
if (test-goal>eps){ printf("%d card(s)\n", i-1);break; }
}
}
return 0;
}

浙公网安备 33010602011771号