题目需要实现的功能比较简单..给定一个card lengths 值,要求计算出最少的cards数目;
In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + ... + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.
card lengths公式:1/2 + 1/3 + 1/4 + ... + 1/(n + 1)
代码实现:
#include <iostream>
using namespace std;
int main() {
float a,b;
int n;
while(cin>>a) {
if(a==0.00) {
break;
}
b=0.0;
for(n=2;n<1000;n++) {
if(b>a) {
cout<<n-2<< " card(s)" <<endl;
break;
}
b+=(float)1/n;
} //end for
} //end while
}
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1045