当前位置:网站首页>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;
}
边栏推荐
- Jinfo of JVM command: view and modify JVM configuration parameters in real time
- Go language learning notes - Gorm use - native SQL, named parameters, rows, tosql | web framework gin (IX)
- 生活中的开销,怎么记账合适
- Cf:c. column swapping [sort + simulate]
- 软件测试的几个关键步骤,你需要知道
- [InstallShield] Introduction
- C. colonne Swapping [tri + Simulation]
- CMD permanently delete specified folders and files
- 解决pod install报错:ffi is an incompatible architecture
- The boss always asks me about my progress. Don't you trust me? (what do you think)
猜你喜欢

Jinfo of JVM command: view and modify JVM configuration parameters in real time
![[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
![[SQL practice] a SQL statistics of epidemic distribution across the country](/img/ba/639a23d87094d24572a69575b565b9.png)
[SQL practice] a SQL statistics of epidemic distribution across the country

Chain storage of stack

话说SQLyog欺骗了我!

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

The boss always asks me about my progress. Don't you trust me? (what do you think)

go-microservice-simple(2) go-Probuffer

软件测试知识储备:关于「登录安全」的基础知识,你了解多少?

Nvisual network visualization
随机推荐
@Detailed differences between pathvariable and @requestparam
每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
Solve pod install error: FFI is an incompatible architecture
How much do you know about clothing ERP?
QT console output in GUI applications- Console output in a Qt GUI app?
JVM命令之 jinfo:实时查看和修改JVM配置参数
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
那些自损八百的甲方要求
Deep clustering: joint optimization of depth representation learning and clustering
你不知道的互联网公司招聘黑话大全
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
Swagger3 configuration
mac版php装xdebug环境(m1版)
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
Flask1.1.4 werkzeug1.0.1 source code analysis: start the process
Rk3399 platform development series explanation (interruption) 13.10, workqueue work queue
cf:C. Column Swapping【排序 + 模擬】
Talking about reading excel with POI
【GNN】图解GNN: A gentle introduction(含视频)
Find duplicate email addresses