当前位置:网站首页>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;
}
边栏推荐
- JVM command - jmap: export memory image file & memory usage
- PTA TIANTI game exercise set l2-003 moon cake test point 2, test point 3 Analysis
- Introduction to yarn (one article is enough)
- PTA ladder game exercise set l2-004 search tree judgment
- JVM命令之- jmap:导出内存映像文件&内存使用情况
- 当我们谈论不可变基础设施时,我们在谈论什么
- Digital IC interview summary (interview experience sharing of large manufacturers)
- 你不知道的互联网公司招聘黑话大全
- 话说SQLyog欺骗了我!
- If you don't know these four caching modes, dare you say you understand caching?
猜你喜欢
@pathvariable 和 @Requestparam的详细区别
Chain storage of stack
How to improve website weight
CTFshow--常用姿势
每秒10W次分词搜索,产品经理又提了一个需求!!!(收藏)
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
Add salt and pepper noise or Gaussian noise to the picture
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
JVM监控及诊断工具-命令行篇
话说SQLyog欺骗了我!
随机推荐
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
Value range of various datetimes in SQL Server 2008
Add salt and pepper noise or Gaussian noise to the picture
PTA 天梯赛练习题集 L2-004 搜索树判断
Reading notes of Clickhouse principle analysis and Application Practice (6)
Go language learning notes - Gorm use - Gorm processing errors | web framework gin (10)
JVM命令之 jstat:查看JVM統計信息
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
980. 不同路径 III DFS
JVM命令之 jinfo:实时查看和修改JVM配置参数
如果不知道这4种缓存模式,敢说懂缓存吗?
Jinfo of JVM command: view and modify JVM configuration parameters in real time
POI excel export, one of my template methods
SubGHz, LoRaWAN, NB-IoT, 物联网
PTA ladder game exercise set l2-002 linked list de duplication
目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
@pathvariable 和 @Requestparam的详细区别
Nvisual network visualization
@Detailed differences between pathvariable and @requestparam
Ten stages of becoming a Senior IC Design Engineer. What stage are you in now?