poj 1003 Hangover 解题报告

题意还是比较容易理解的,题上已经给出了公式。求1/2 + 1/3 + 1/4 + ... + 1/(n + 1)>=x的最小n的值,稍微注意点的就是浮点型了,貌似很多人都WA过,都是错在浮点数的。。

代码实现
#include <iostream>


using namespace std;


int main()
{
float f;
while(cin>>f,f)
{
float n=2.0;
float sum=0.0;
while(1)
{
sum
+=1.0/n;
if(sum>=f) break;
n
+=1.0;
}
cout
<<(int)n-1<<" card(s)"<<endl;
}


return 0;
}
原文地址:https://www.cnblogs.com/andyidea/p/poj1003.html