Posted on 2011-11-10 10:04
C小加 閱讀(1690)
評論(0) 編輯 收藏 引用 所屬分類:
解題報告
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;
}