POJ 3253 Fence Repair
2010-12-13 20:44
260 查看
解题思路:基于最小堆实现Haffman
NULL
NULL
#include <iostream> using namespace std; int n,plank[20001]; void heapAdjust(int s) { int i,exp; for(i=s;i<=(n/2);) { exp=((i*2+1)<=n&&plank[i*2+1]<plank[i*2])?1:0; if(plank[i]>plank[i*2+exp]) swap(plank[i],plank[i*2+exp]),i=i*2+exp; else break; } } int main() { int i,t; __int64 ans=0; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d",&plank[i]); for(i=n/2;i>=1;i--)heapAdjust(i); while (n>1) { t=plank[1];plank[1]=plank ;n--; heapAdjust(1); t+=plank[1];plank[1]=t; heapAdjust(1); ans+=t; } printf("%I64d\n",ans); return 0; }
相关文章推荐
- poj 3253 Fence Repair
- POJ 3253 Fence Repair(贪心 + 优先队列)
- POJ - 3253 Fence Repair(贪心)
- POJ 3253 Fence Repair(贪心+优先队列)
- poj 3253 Fence Repair
- POJ 3253 Fence Repair (贪心&优先队列)
- POJ 3253 Fence Repair (霍夫曼编码 + 最小堆)
- POJ:3253 Fence Repair(优先队列)
- Poj 3253 Fence Repair【贪心】
- poj [3253] Fence Repair 赫夫曼树
- (哈夫曼树思想 )poj 3253 Fence Repair
- POJ 3253 Fence Repair(优先队列)
- 【POJ 3253 Fence Repair】+ 优先队列
- POJ 3253 Fence Repair 哈夫曼树 优先队列
- POj 3253 Fence Repair(修农场栅栏,锯木板)(小根堆 + 哈弗曼建树得最小权值思想 )
- POJ 3253 Fence Repair(哈夫曼树)
- POJ 3253 Fence Repair【哈夫曼树】
- POJ 3253 Fence Repair(贪心, Huffman编码)
- poj 3253 Fence Repair(优先队列+贪心)
- POJ 3253 优先队列 Fence Repair