当前位置:网站首页>3531. Huffman tree
3531. Huffman tree
2022-07-07 06:13:00 【Ray. C.L】
Ideas : Simulating Huffman tree with heap
Code :
#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;
}
边栏推荐
- 10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
- CTFshow--常用姿势
- Sequential storage of stacks
- Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)
- Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
- STM32 key state machine 2 - state simplification and long press function addition
- Flask1.1.4 werkzeug1.0.1 source code analysis: start the process
- Storage of dental stem cells (to be continued)
- Introduction to yarn (one article is enough)
- Rk3399 platform development series explanation (interruption) 13.10, workqueue work queue
猜你喜欢
深度聚类:将深度表示学习和聚类联合优化
【GNN】图解GNN: A gentle introduction(含视频)
Check Point:企业部署零信任网络(ZTNA)的核心要素
[SQL practice] a SQL statistics of epidemic distribution across the country
The boss always asks me about my progress. Don't you trust me? (what do you think)
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
Chain storage of stack
DC-7靶机
驱动开发中platform设备驱动架构详解
3531. 哈夫曼树
随机推荐
Detailed explanation of platform device driver architecture in driver development
Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
Sequential storage of stacks
980. Different path III DFS
解决pod install报错:ffi is an incompatible architecture
Bypass open_ basedir
Ctfshow-- common posture
【SQL实战】一条SQL统计全国各地疫情分布情况
Vscode for code completion
PTA ladder game exercise set l2-002 linked list de duplication
SAP Spartacus checkout 流程的扩展(extend)实现介绍
蚂蚁庄园安全头盔 7.8蚂蚁庄园答案
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
Data storage 3
Industrial Finance 3.0: financial technology of "dredging blood vessels"
高并发大流量秒杀方案思路
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
Storage of dental stem cells (to be continued)
jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取