当前位置:网站首页>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;
}
边栏推荐
- 外设驱动库开发笔记43:GPIO模拟SPI驱动
- PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
- 那些自损八百的甲方要求
- Cf:c. column swapping [sort + simulate]
- Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
- 10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
- Red Hat安装内核头文件
- Win configuration PM2 boot auto start node project
- 绕过open_basedir
- 牙齿干细胞的存储问题(未完待续)
猜你喜欢

PowerPivot——DAX(函数)

Jstat of JVM command: View JVM statistics

EMMC print cqhci: timeout for tag 10 prompt analysis and solution

404 not found service cannot be reached in SAP WebService test

cf:C. Column Swapping【排序 + 模擬】

如何在Touch Designer 2022版中设置解决Leap Motion不识别的问题?

cf:C. Column Swapping【排序 + 模拟】
![[InstallShield] Introduction](/img/df/4522d06510ff918d00659b8358368f.jpg)
[InstallShield] Introduction

mac版php装xdebug环境(m1版)

Financial risk control practice - decision tree rule mining template
随机推荐
PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
Three level menu data implementation, nested three-level menu data
Solve pod install error: FFI is an incompatible architecture
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
CTFshow--常用姿势
Personal imitation SSM framework
[FPGA tutorial case 14] design and implementation of FIR filter based on vivado core
The solution of a simple algebraic problem
Apple CMS V10 template /mxone Pro adaptive film and television website template
Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
Nvisual network visualization
PTA 天梯赛练习题集 L2-002 链表去重
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
Bat instruction processing details
Red Hat安装内核头文件
mac版php装xdebug环境(m1版)
jvm命令之 jcmd:多功能命令行
盘点国内有哪些EDA公司?
【日常训练--腾讯精选50】292. Nim 游戏
From "running distractor" to data platform, Master Lu started the road of evolution