poj1607

题意:一叠卡片,用一种摆法,要求每张卡片短边与桌檐平行,并让他们超出桌檐尽量多,问能超出桌檐多少。

POJ <wbr>1607

分析:对于n张卡片的最佳摆法,我们只需要在n-1张卡片的摆法下面加一张边缘与桌檐重合的卡片,并将所有卡片一起向桌檐外移动。对于一种最佳摆法,其中心一定在桌檐上,所以一定符合杠杆原理,支点是桌檐。那么对于n张卡片的情况,我们假设第n张向外移动了x,那么前n-1张的重心就在桌檐外x,因为他们的重心在n-1张卡片时原本在桌檐上。第n张卡片的重心在桌檐内0.5-x处,那么我们可以列出杠杆平衡方程:(0.5-x)*1=x*(n-1)

解得:x=1/(2n)。那么我们所要的答案也就是1/2+1/(2×2)+1/(2×3)+...

View Code
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;

int n;

int main()
{
    //freopen("t.txt", "r", stdin);
    puts("Cards  Overhang");
    while (~scanf("%d", &n))
    {
        double ans = 0;
        for (int i = 1; i <= n; i++)
            ans += 1.0 / (i * 2);
        printf("%5d%10.3f\n", n, ans);    
    }    
    return 0;
}
原文地址:https://www.cnblogs.com/rainydays/p/2862235.html