sgu 203
来源:互联网 发布:信捷xc3软件 编辑:程序博客网 时间:2024/04/29 03:33
构造哈夫曼树,开始乱搞,蛤蛤。
时间复杂度:
事实上正解应该是
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>#include<queue>const int MAXN = 500005;typedef std::priority_queue<long long,std::vector<long long>,std::greater<long long> > Heap_ll;int n, p[MAXN];Heap_ll heap;long long ans;int main(){#ifndef ONLINE_JUDGE freopen("sgu203.in","r",stdin); freopen("sgu203.out","w",stdout);#endif scanf("%d",&n); for(int i = 1; i <= n; i++) scanf("%d",&p[i]), heap.push(p[i]); for(int i = 1; i < n; i++) { long long a, b; a = heap.top(), heap.pop(); b = heap.top(), heap.pop(); heap.push(a + b), ans += a + b; } printf("%I64d\n",ans); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0; }
0 0
- sgu 203
- sgu-203 Hyperhuffman
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- sgu 120
- sgu 116
- python socket的c/s模式
- ionic使用记录----栅格模式
- strtoul 函数
- Java集合和数组的排序方式总结
- mysql中的一些错误总结
- sgu 203
- 泊松分布的来源—公式推导—应用
- 关于WebView的那些事
- REST与SOA两种架构的异同比较
- opencv源码解析之(3):特征点检查前言1
- linux各个目录内容
- Unity判断手势触摸的类型 ,判断手势的滑动方向,并获取刚触摸以及触摸结束事的坐标
- 面向对象设计模式与原则(一)
- javascript基本函数