ccz181078

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

Description

Input

第一行正整数 N M

Output

一行(有换行符),L,表示水平延伸最远的整数距离 (不大于答案的最大整数)

贪心地把最高的书尽量向右放可以得到最优解,因而最高的书的重心在次高的书边缘,最上面两本书的重心在第三本书边缘...

可以发现ans=m/2+m/4+m/6+...+m/2n

答案为小于 调和级数前n项和乘m除以2 的最大整数,因此可以用调和级数的近似前缀和公式求,当n较小时由于公式误差较大可以暴力求。

#include<cstdio>
#include<cmath>
int main(){
    long long n;
    int m;
    double s=0;
    scanf("%lld%d",&n,&m);
    if(n<100)for(int i=1;i<=n;i++)s+=1.0/i;
    else s=log(n)+1.0/(2*n+exp(-1))+0.5772156649;
    printf("%d",(int)(m*s/2-1e-5));
    return 0;
}

 

posted on 2016-03-20 11:02  nul  阅读(179)  评论(0编辑  收藏  举报