zoukankan      html  css  js  c++  java
  • hdu1330(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1330

    分析:经典问题,n 块相同的木板重叠,最多能够伸出桌面多远

    对于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)。可以推出,如果每块木板都是单位长,那么 n 块木板可以伸出桌面 (1 + 1/2 + 

    1/3 + … + 1/n) / 2 个单位的长度。

    参考:http://gd2011.teacher.com.cn/UserLog/UserLogComment.aspx?UserlogID=15319

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <cstdlib>
    #include <vector>
    #include <set>
    #include <map>
    #define LL long long
    #define inf 1<<30
    #define mod 1000000007
    #define N 100010
    using namespace std;
    int main()
    {
        int n;
        double a[100010];
        a[1] = 0.5;
        for(int i = 2; i <= 100000; i++)
        a[i] = a[i-1] + 1.0/i/2;
        printf("# Cards  Overhang
    ");
        while(scanf("%d",&n)>0)
        {
            printf("%5d%10.3lf
    ",n,a[n]);
        }
    }
    View Code
  • 相关阅读:
    1010考试T1
    P5631 最小mex生成树 分治 并查集
    P4366 [Code+#4]最短路 建图 最短路
    P1654 OSU! 期望概率DP
    7.26集训
    7.25集训
    7.23集训
    7.22集训
    7.21test
    7.12test
  • 原文地址:https://www.cnblogs.com/lienus/p/4133384.html
Copyright © 2011-2022 走看看