传送门

Luogu

解题思路

\(k\) 叉 \(\text{Huffman}\) 树板子题,至于最长串最短,只要同样权值的优先考虑深度小的就好了。

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} typedef long long LL;
const int _ = 100010; int n, k; struct node{ LL w; int h; };
inline bool operator < (const node& a, const node& b)
{ return a.w == b.w ? a.h > b.h : a.w > b.w; }
priority_queue < node > Q; int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
#endif
read(n), read(k);
for (rg int i = 1; i <= n; ++i) {
LL w; read(w), Q.push((node) { w, 1 });
}
while ((n - 1) % (k - 1) != 0) Q.push((node) { 0, 1 }), ++n;
LL ans = 0;
while (Q.size() != 1) {
int mx = 0; LL tmp = 0;
for (rg int i = 1; i <= k; ++i)
tmp += Q.top().w, mx = max(mx, Q.top().h), Q.pop();
ans += tmp, Q.push((node) { tmp, mx + 1 });
}
printf("%lld\n%d\n", ans, Q.top().h - 1);
return 0;
}

完结撒花 \(qwq\)

最新文章

  1. Blender 之 Splash 代码分析
  2. .NET平台开源项目速览(4).NET文档生成工具ADB及使用
  3. [WCF编程]7.实例上下文模式
  4. 一步一步安装UEFI分区方式的windows 10 企业版
  5. Android:学习AIDL,这一篇文章就够了(上)
  6. 飞锐GIS开发基础系列
  7. android进入adb shell步骤及修改sqlite数据库文件的权限
  8. IOS9关于搜索的认识和实现
  9. 深入研究.NET Core的本地化机制
  10. pandas 时间格式转换
  11. 移动前端webApp开发点滴积累20140524
  12. CodeForces1065F 树形dp
  13. 手机调试 ---- Node启动服务
  14. mac下hbase安装
  15. mysql contact_ws函数 字符串被截断问题
  16. IOLI crackme分析——从应用中学习使用radare2
  17. Weblogic申请和配置SSL证书
  18. 2_C语言中的数据类型 (一)2.1.常量和字符串常量
  19. 在CentOS 7中使用VS Code编译调试C++项目
  20. Unity3d 摇杆奖励

热门文章

  1. JavaSE复习~常量、变量、关键字、标识符
  2. ubuntu安装zsh终端
  3. ES-9200端口与9300端口
  4. LeetCode 234. Palindrome Linked List(判断是否为回文链表)
  5. 第七节:Vuejs路由交互及后台系统路由案例
  6. SVN 锁定无法提交命令执行失败
  7. GCC 升级
  8. 操作系统OS,Python - 生产者消费者模型
  9. JS获取CHECKBOX的值 AND 两个CHECKBOX 循环选中
  10. python 基础之深浅拷贝