当前位置:网站首页>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;
}
边栏推荐
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- make makefile cmake qmake都是什么,有什么区别?
- [shell] clean up nohup Out file
- cf:C. Column Swapping【排序 + 模擬】
- jvm命令之 jcmd:多功能命令行
- 693. 行程排序
- SQL Server 2008 各种DateTime的取值范围
- Add salt and pepper noise or Gaussian noise to the picture
- Determine whether the file is a DICOM file
猜你喜欢

ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略

目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss

Reading notes of Clickhouse principle analysis and Application Practice (6)

一个简单的代数问题的求解

职场经历反馈给初入职场的程序员

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

话说SQLyog欺骗了我!

老板总问我进展,是不信任我吗?(你觉得呢)

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

Bat instruction processing details
随机推荐
Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?
Nvisual network visualization
Introduction to the extension implementation of SAP Spartacus checkout process
Storage of dental stem cells (to be continued)
绕过open_basedir
jvm命令之 jcmd:多功能命令行
【日常训练--腾讯精选50】292. Nim 游戏
关于STC单片机“假死”状态的判别
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture
If you don't know these four caching modes, dare you say you understand caching?
[cloud native] what is the microservice architecture?
yarn入门(一篇就够了)
Mysql-centos7 install MySQL through yum
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
Flask1.1.4 werkzeug1.0.1 source code analysis: start the process
盘点国内有哪些EDA公司?
JVM命令之- jmap:导出内存映像文件&内存使用情况
VScode进行代码补全
k8s运行oracle
Jstat pour la commande JVM: voir les statistiques JVM