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\n");
    while(scanf("%d",&n)>0)
    {
        printf("%5d%10.3lf\n",n,a[n]);
    }
}
View Code

 

转载于:https://www.cnblogs.com/lienus/p/4133384.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值