当前位置:网站首页>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;
}
边栏推荐
- cf:C. Column Swapping【排序 + 模拟】
- 老板总问我进展,是不信任我吗?(你觉得呢)
- 话说SQLyog欺骗了我!
- [InstallShield] Introduction
- [SQL practice] a SQL statistics of epidemic distribution across the country
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- Jstat of JVM command: View JVM statistics
- 外设驱动库开发笔记43:GPIO模拟SPI驱动
- Apple CMS V10 template /mxone Pro adaptive film and television website template
- How to improve website weight
猜你喜欢

The solution of a simple algebraic problem

蚂蚁庄园安全头盔 7.8蚂蚁庄园答案

JVM命令之 jstat:查看JVM統計信息

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

每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)

Red hat install kernel header file

JVM命令之 jstat:查看JVM统计信息

Mac version PHP installed Xdebug environment (M1 version)
![[InstallShield] Introduction](/img/df/4522d06510ff918d00659b8358368f.jpg)
[InstallShield] Introduction

How to improve website weight
随机推荐
那些自损八百的甲方要求
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
Ctfshow-- common posture
搞懂fastjson 对泛型的反序列化原理
【SQL实战】一条SQL统计全国各地疫情分布情况
[daily training -- Tencent selected 50] 292 Nim games
Question 102: sequence traversal of binary tree
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
Solve pod install error: FFI is an incompatible architecture
window下面如何安装swoole
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
解决pod install报错:ffi is an incompatible architecture
牙齿干细胞的存储问题(未完待续)
Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();
mac版php装xdebug环境(m1版)
360织语发布7.0新品 为党政军、央国企打造专属“统一数字工作空间”
Career experience feedback to novice programmers
Change the original style of UI components
外设驱动库开发笔记43:GPIO模拟SPI驱动
职场经历反馈给初入职场的程序员