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;
}

 

posted @ 2016-07-25 22:27  J_Harden  阅读(102)  评论(0)    收藏  举报