NYOJ地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=156
題意還是比較容易理解的,題上已經給出了公式。求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;
}
#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;
}