Posted on 2011-11-10 10:04
C小加 閱讀(1692)
評論(0) 編輯 收藏 引用 所屬分類:
解題報(bào)告
NYOJ地址:
http://acm.nyist.net/JudgeOnline/problem.php?pid=156
題意還是比較容易理解的,題上已經(jīng)給出了公式。求1/2
+ 1/3
+ 1/4
+ ...
+ 1/(
n + 1)>=x的最小n的值,稍微注意點(diǎn)的就是浮點(diǎn)型了,貌似很多人都WA過,都是錯(cuò)在浮點(diǎn)數(shù)的。。
#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;
}