POJ 3253
来源:互联网 发布:淘宝头像店招在线制作 编辑:程序博客网 时间:2024/06/05 10:50
Huffman树 详见http://blog.csdn.net/shuangde800/article/details/7341289
然而我用小根堆过的
跟合并果子一样
#include<cstdio>#include<cstdlib>#include<iostream>#include<algorithm>using namespace std;long long i,j,k,m,n,a[20001],ans;inline bool cmp(long long a,long long b){return a>b;}inline long long readint(){ char c=getchar();long long x=0; while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar(); return x;}int main(){ n=readint(); for(i=1;i<=n;i++)a[i]=readint(); make_heap(a+1,a+n+1,cmp); while(n>1) { pop_heap(a+1,a+n+1,cmp); pop_heap(a+1,a+n,cmp); a[n-1]+=a[n]; ans+=a[n-1];n--; push_heap(a+1,a+n+1,cmp); } cout<<ans<<endl; return 0;}
0 0
- POJ 3253
- poj 3253
- poj 3253
- poj 3253
- poj----3253
- poj.3253
- poj 3253
- POJ 3253
- poj 3253
- poj-3253
- POJ-3253
- POJ 3253
- poj 3253
- poj-3253
- poj-3253
- POJ 3253
- POJ 3253
- POJ 3253
- Linux内核分析 实验五:分析system_call中断处理过程
- opencv鼠标绘制矩形和截取图像的矩形区域
- 机器学习中常用的优化方法
- Android系统自带样式(android:theme)(转)
- MyBatis关于映射SQL语句的总结
- POJ 3253
- 无限极分类
- Offer题8 旋转数组的最小值
- 项目1-三角形雏形用set和get算周长和面积
- 共同学习Spring源码--ContextLoaderListener和ContextCleanupListener
- POJ 2236
- 2016.03.27(o(︶︿︶)o 唉)
- SQLServer 导出数据库表结构
- 深度学习在图像识别中的研究进展与展望