当前位置:网站首页>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;
}
边栏推荐
- @pathvariable 和 @Requestparam的详细区别
- Subghz, lorawan, Nb IOT, Internet of things
- Find duplicate email addresses
- What EDA companies are there in China?
- PowerPivot——DAX(函数)
- 你不知道的互联网公司招聘黑话大全
- [InstallShield] Introduction
- PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
- Understand the deserialization principle of fastjson for generics
- win系统下安装redis以及windows扩展方法
猜你喜欢
Jstack of JVM command: print thread snapshots in JVM
每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
win系统下安装redis以及windows扩展方法
jmeter 函数助手 — — 随机值、随机字符串、 固定值随机提取
Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
关于STC单片机“假死”状态的判别
JVM命令之 jstack:打印JVM中线程快照
From "running distractor" to data platform, Master Lu started the road of evolution
Say sqlyog deceived me!
随机推荐
Solve pod install error: FFI is an incompatible architecture
SAP Spartacus checkout 流程的扩展(extend)实现介绍
SQL Server 2008 各种DateTime的取值范围
一个简单的代数问题的求解
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
go-microservice-simple(2) go-Probuffer
如果不知道这4种缓存模式,敢说懂缓存吗?
postgresql 数据库 timescaledb 函数time_bucket_gapfill()报错解决及更换 license
If you don't know these four caching modes, dare you say you understand caching?
JVM命令之- jmap:导出内存映像文件&内存使用情况
云加速,帮助您有效解决攻击问题!
Red Hat安装内核头文件
高并发大流量秒杀方案思路
mac版php装xdebug环境(m1版)
搞懂fastjson 对泛型的反序列化原理
A very good JVM interview question article (74 questions and answers)
生活中的开销,怎么记账合适
Crudini 配置文件编辑工具
cf:C. Column Swapping【排序 + 模拟】
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();