荷马史诗
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); }
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 源码浅析:SpringBoot main方法结束为什么程序不停止
· C#性能优化:为何 x * Math.Sqrt(x) 远胜 Math.Pow(x, 1.5)
· 本可避免的P1事故:Nginx变更导致网关请求均响应400
· 还在手写JSON调教大模型?.NET 9有新玩法
· 复杂业务系统线上问题排查过程
· AI 的力量,开发者的翅膀:欢迎使用字节旗下的 AI 原生开发工具 TRAE
· 「闲聊文」准大三的我,思前想后还是不搞java了
· C#性能优化:为何 x * Math.Sqrt(x) 远胜 Math.Pow(x, 1.5)
· 千万级的大表如何新增字段?
· 《HelloGitHub》第 112 期