当前位置:网站首页>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;
}
边栏推荐
- 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
- Classic questions about data storage
- Check Point:企业部署零信任网络(ZTNA)的核心要素
- [cloud native] what is the microservice architecture?
- JVM监控及诊断工具-命令行篇
- R language [logic control] [mathematical operation]
- JVM命令之 jstat:查看JVM統計信息
- Value range of various datetimes in SQL Server 2008
- Things about data storage 2
- Jinfo of JVM command: view and modify JVM configuration parameters in real time
猜你喜欢
JVM命令之 jinfo:实时查看和修改JVM配置参数
The solution of a simple algebraic problem
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
[SQL practice] a SQL statistics of epidemic distribution across the country
Three level menu data implementation, nested three-level menu data
SAP Spartacus checkout 流程的扩展(extend)实现介绍
3428. 放苹果
【SQL实战】一条SQL统计全国各地疫情分布情况
JVM命令之- jmap:导出内存映像文件&内存使用情况
jvm命令之 jcmd:多功能命令行
随机推荐
往图片添加椒盐噪声或高斯噪声
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
STM32按键状态机2——状态简化与增加长按功能
Determine whether the file is a DICOM file
Mysql-centos7 install MySQL through yum
[FPGA tutorial case 14] design and implementation of FIR filter based on vivado core
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
老板总问我进展,是不信任我吗?(你觉得呢)
Things about data storage 2
404 not found service cannot be reached in SAP WebService test
Understand the deserialization principle of fastjson for generics
@pathvariable 和 @Requestparam的详细区别
Question 102: sequence traversal of binary tree
SAP ABAP BDC (batch data communication) -018
关于STC单片机“假死”状态的判别
PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
PTA ladder game exercise set l2-002 linked list de duplication
Apple CMS V10 template /mxone Pro adaptive film and television website template
Digital IC interview summary (interview experience sharing of large manufacturers)
Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture