P2168 [NOI2015] 荷马史诗(k 叉huffman)

Lisa

这要构建一个什么玩意

K进制haffum树

然后节点数不够咋办

加空节点‘

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define int long long
using namespace std;
int n,k;
struct wo{
    int h;
    int l;
    friend bool operator < (const wo x,const wo y){
        if(x.l==y.l) return x.h>y.h;
        return x.l>y.l;
    }
};
priority_queue<wo> q;
int x,xx;
int cnt;
int ans;
int len;
signed main(){
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;++i){
        scanf("%lld",&x);
            q.push((wo){
                1,x     
            });
    }
    if((n-1)%(k-1)!=0)
     xx=(k-1)-(n-1)%(k-1);
    for(int i=1;i<=xx;++i){
        q.push((wo){
            1,0
        });
    }
    cnt=xx+n;
    while(cnt>1){
        int th=0;
        int ts=0;
        for(int i=1;i<=k;++i){
            wo tem=q.top();
            q.pop();
            th=max(th,tem.h);
            ts+=tem.l;
        }
        q.push((wo){
            th+1,ts});
        ans+=ts;
        cnt-=(k-1);
    }
    printf("%lldn%lld",ans,q.top().h-1);
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇