POJ 3253
来源:互联网 发布:网络拓扑结构连线最短 编辑:程序博客网 时间:2024/06/08 16:42
题意:要将一块很长的木板切割成N块。准备切成L1,L2,L3……LN,每次切断木板时,需要的开销为木板的长度。要求出切割完最小的开销。
求最短的带全路径长度,利用哈夫曼编码的思想贪心的求得结果。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <map>#include <queue>using namespace std;typedef long long ll;int main(){ int n; while(~scanf("%d",&n)){ priority_queue<ll>q; ll temp; for(int i = 0;i < n;i++){ scanf("%I64d",&temp); q.push(-temp); } ll ans = 0; ll t1,t2; while(!q.empty()){ t1 = -q.top(); q.pop(); if(q.empty()) break; t2 = -q.top(); q.pop(); ans += t1+t2; //printf("%d ",ans); q.push(-(t1+t2)); } printf("%I64d\n",ans); } 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
- XTU_1184 A Love Letter
- css抖动的样式源码
- 当单元格中的内容长度大于表列的宽度时显示省略号.
- unity的本地化存储PlayerPrefs
- HDOJ 2294 - Pendant(DP+矩阵快速幂)
- POJ 3253
- 虚拟桌面的本质论
- Linux环境下段错误的产生原因及调试方法小结
- 『ANDROID』 在Android开发过程中,常Android 更新UI的两种方法——handler和runOnUiThread()
- 堆和栈的区别
- openwrt 3G无线上网卡拨号--以华为EC189为例
- cxf整合spring
- 阿里面试重点总结
- Linux进程间通信——消息队列(一)