How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We‘re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. 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.
附上AC代码:
#include <iostream> #include <cstdio> #include <string> #include <cmath> #include <iomanip> #include <ctime> #include <climits> #include <cstdlib> #include <cstring> #include <algorithm> typedef unsigned int UI; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; const double PI = 3.14159265; const double E = 2.71828182846; int main() { using namespace std; std::ios::sync_with_stdio(false); double len; while (cin >> len && len > 0) { double sum = 0; int i; for (i=2; sum<len; i++) sum += 1.0/i; cout << i-2 << " card(s)\n"; } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/silenceneo/article/details/47776339