poj 3253 类似霍夫曼贪心思想,优先队列的运用
2013-08-19 18:45
309 查看
每次选取堆里面最短的两根木头相加,再将所得和重新加入堆中,直到堆的size小于2
View Code
View Code
#include<queue> #include<stdio.h> #include<string.h> #include<vector> using namespace std; struct mycmp{ bool operator()(const int &a,const int &b) { return a>b; } }; int main() { priority_queue<__int64,vector<__int64>,mycmp> Q; int n,num; int i,j; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { scanf("%d",&num); Q.push(num); } __int64 a,b,sum=0; while(Q.size()>=2) { a=Q.top(); Q.pop(); b=Q.top(); Q.pop(); Q.push(a+b); sum+=(a+b); } printf("%I64d\n",sum); } return 0; }
相关文章推荐
- poj 3253 类似霍夫曼贪心思想,优先队列的运用
- POJ 3253 Fence Repair(优先队列+思维贪心)(哈夫曼树算法)
- poj3253——哈夫曼树思想 + 优先队列解决
- Poj 3253 Fence Repair (贪心加优先队列的应用)
- POJ—3253—Fence Repair—【贪心】【优先队列】
- poj 2431 poj 3253 优先队列的运用
- poj 3253 Fence Repair (贪心+哈弗曼思想+优先队列)
- POJ 3253 Fence Repair 优先队列
- POJ 3253 Fence Repair 题解(优先队列实现哈夫曼树)
- poj 3190 贪心 + 优先队列优化
- POJ 题目3253 Fence Repair(优先队列,哈弗曼)
- POJ3253-- Fence Repair【优先队列】
- PAT 修理牧场(25)(Huffman问题,优先队列priority_queue)(与poj 3253 一模一样的思路)
- POJ 3614 Sunscreen 优先队列 贪心
- POJ 3614 Sunscreen 优先队列 贪心
- 优先队列 POJ 3253 Fence Repair
- 优先队列:POJ No 3614 Sunscreen 贪心
- POJ 3253 - Fence Repai ( 优先队列 )
- POJ 3614 Sunscreen [贪心 + 优先队列] 《挑战程序设计竞赛》2.4
- 挑战程序设计竞赛 POJ 3253 贪心+霍夫曼思想+优先队列