zoukankan      html  css  js  c++  java
  • 荷马史诗

    Solution

    看到这道题,可以想到和合并果子类似,之后拓展成k叉合并果子就可以了,注意最下面一层不满时要补满

    Code

    #include<bits/stdc++.h>
    using namespace std;
    #define max(a,b) (a>b?a:b)
    typedef long long LL; 
    struct node{
        LL w,h;
        node(LL W , LL H){w=W,h=H;}
    };
    bool operator < (node a,node b){//不知道为什么不能用大于
        return (a.w>b.w)||(a.w==b.w&&a.h>b.h);
    }
    priority_queue<node,vector<node>,less<node> > q;
    int n,k,cnt;
    LL x,t,mh,ans;
    int main(){
        scanf("%d%d",&n,&k);
        for(int i=1;i<=n;i++)scanf("%lld",&x),q.push(node(x,1));
        if((n-1)%(k-1))cnt=k-1-(n-1)%(k-1);
        for(int i=1;i<=cnt;i++)q.push(node(0,1));
        cnt+=n;
        while(cnt>1){
            t=mh=0;
            for(int i=1;i<=k;i++){
                t+=q.top().w;
                mh=max(mh,q.top().h);
                q.pop();
            }
            ans+=t;
            q.push(node(t,mh+1));
            cnt-=k-1;
        }
        printf("%lld
    %lld
    ",ans,q.top().h-1);
    }
  • 相关阅读:
    情人节玫瑰花
    Yii2美化confirm
    apache ab压力测试
    Yii2的Debug工具
    yii2的扩展程序包
    slim
    composer使用
    打印
    yii的csv导出
    ajax文件下载
  • 原文地址:https://www.cnblogs.com/coder-cjh/p/11415384.html
Copyright © 2011-2022 走看看