当前位置:网站首页>3531. 哈夫曼树
3531. 哈夫曼树
2022-07-07 01:09:00 【Ray.C.L】

思路:用堆模拟哈夫曼树
代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
priority_queue<int, vector<int>, greater<int>> q;
int n;
scanf("%d", &n);
while(n -- ){
int x;
scanf("%d", &x);
q.push(x);
}
int sum = 0, res = 0;
while(q.size() > 1){
int a = q.top();
q.pop();
int b = q.top();
q.pop();
sum = a + b;
q.push(sum);
res += sum;
}
cout << res << endl;
return 0;
}
边栏推荐
- Industrial Finance 3.0: financial technology of "dredging blood vessels"
- cf:C. Column Swapping【排序 + 模拟】
- Randomly generate session_ id
- 解决pod install报错:ffi is an incompatible architecture
- Determine whether the file is a DICOM file
- ML's shap: Based on the adult census income binary prediction data set (whether the predicted annual income exceeds 50K), use the shap decision diagram combined with the lightgbm model to realize the
- @pathvariable 和 @Requestparam的详细区别
- Input of native applet switches between text and password types
- STM32 key state machine 2 - state simplification and long press function addition
- PowerPivot - DAX (function)
猜你喜欢

PTA 天梯赛练习题集 L2-004 搜索树判断

How to improve website weight

3428. 放苹果

Loss function and positive and negative sample allocation in target detection: retinanet and focal loss

On the discrimination of "fake death" state of STC single chip microcomputer

JVM命令之 jinfo:实时查看和修改JVM配置参数

驱动开发中platform设备驱动架构详解

Get the way to optimize the one-stop worktable of customer service

SubGHz, LoRaWAN, NB-IoT, 物联网

职场经历反馈给初入职场的程序员
随机推荐
Three level menu data implementation, nested three-level menu data
测试开发基础,教你做一个完整功能的Web平台之环境准备
Add salt and pepper noise or Gaussian noise to the picture
STM32按键状态机2——状态简化与增加长按功能
Sequential storage of stacks
Web authentication API compatible version information
Data storage 3
SAP ABAP BDC (batch data communication) -018
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
Randomly generate session_ id
往图片添加椒盐噪声或高斯噪声
Get the way to optimize the one-stop worktable of customer service
Introduction to the extension implementation of SAP Spartacus checkout process
@pathvariable 和 @Requestparam的详细区别
Industrial Finance 3.0: financial technology of "dredging blood vessels"
Cloud acceleration helps you effectively solve attack problems!
zabbix_ Get test database failed
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
Solve pod install error: FFI is an incompatible architecture
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU