当前位置:网站首页>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;
}
边栏推荐
- Digital IC interview summary (interview experience sharing of large manufacturers)
- Deep clustering: joint optimization of depth representation learning and clustering
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- Ctfshow-- common posture
- CMD permanently delete specified folders and files
- Dc-7 target
- 绕过open_basedir
- 往图片添加椒盐噪声或高斯噪声
- Apple CMS V10 template /mxone Pro adaptive film and television website template
- C. colonne Swapping [tri + Simulation]
猜你喜欢

Three level menu data implementation, nested three-level menu data

404 not found service cannot be reached in SAP WebService test

Check point: the core element for enterprises to deploy zero trust network (ztna)

每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
![[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree](/img/4c/16bb943e517c7b703996715632e6ca.png)
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree

From "running distractor" to data platform, Master Lu started the road of evolution

Jstat pour la commande JVM: voir les statistiques JVM

Apple CMS V10 template /mxone Pro adaptive film and television website template

Financial risk control practice - decision tree rule mining template

The solution of a simple algebraic problem
随机推荐
If you don't know these four caching modes, dare you say you understand caching?
Flinksql read / write PgSQL
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
[InstallShield] Introduction
What EDA companies are there in China?
Dc-7 target
【FPGA教程案例14】基于vivado核的FIR滤波器设计与实现
测试开发基础,教你做一个完整功能的Web平台之环境准备
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
Cloud acceleration helps you effectively solve attack problems!
Harmonyos practice - Introduction to development, analysis of atomized services
JVM命令之- jmap:导出内存映像文件&内存使用情况
SAP Spartacus checkout 流程的扩展(extend)实现介绍
盘点国内有哪些EDA公司?
cf:C. Column Swapping【排序 + 模拟】
linear regression
How much do you know about clothing ERP?
POI excel export, one of my template methods
Industrial Finance 3.0: financial technology of "dredging blood vessels"
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程