标签:scan define less std its ret bool operator amp
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\n%lld\n",ans,q.top().h-1); }
标签:scan define less std its ret bool operator amp
原文地址:https://www.cnblogs.com/coder-cjh/p/11415384.html