当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Nvisual network visualization

一名普通学生的大一总结【不知我等是愚是狂,唯知一路向前奔驰】

SAP Spartacus checkout 流程的扩展(extend)实现介绍

Red Hat安装内核头文件

DC-7靶机

JVM命令之 jstack:打印JVM中线程快照

Industrial Finance 3.0: financial technology of "dredging blood vessels"

Question 102: sequence traversal of binary tree

【FPGA教程案例14】基于vivado核的FIR滤波器设计与实现

EMMC print cqhci: timeout for tag 10 prompt analysis and solution
随机推荐
JVM命令之 jstat:查看JVM统计信息
Question 102: sequence traversal of binary tree
Value range of various datetimes in SQL Server 2008
Database notes 04
JVM命令之 jstat:查看JVM統計信息
MFC BMP sets the resolution of bitmap, DPI is 600 points, and gdiplus generates labels
980. Different path III DFS
【GNN】图解GNN: A gentle introduction(含视频)
STM32 key state machine 2 - state simplification and long press function addition
Career experience feedback to novice programmers
Flask1.1.4 werkzeug1.0.1 source code analysis: start the process
JVM监控及诊断工具-命令行篇
linear regression
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
A very good JVM interview question article (74 questions and answers)
vim映射大K
Introduction to yarn (one article is enough)
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
If you don't know these four caching modes, dare you say you understand caching?