poj 3253 Fence Repair (优先队列)
来源:互联网 发布:数据库包括哪些语句 编辑:程序博客网 时间:2024/05/21 20:23
///优先队列,每次取两个最小的木板的长度,再把这个长度放进队列,反复取# include <stdio.h># include <algorithm># include <iostream># include <string.h># include <queue># include <vector>using namespace std;///长度小的放在前面class cmp{public: bool operator ()(const __int64 a,const __int64 b)const { return a>b; }};int main(){ int n; __int64 temp,sum,p1,p2; while(~scanf("%d",&n)) { priority_queue<__int64,vector<__int64>,cmp>q;///定义优先队列 while(n--) { scanf("%I64d",&temp); q.push(temp); } sum=0; while(q.size()>1) { p1=q.top(); q.pop(); p2=q.top(); q.pop(); temp=p1+p2; sum+=temp; q.push(temp); } printf("%I64d\n",sum); } return 0;}
0 0
- poj 3253 Fence Repair 优先队列维护
- POJ 3253 优先队列 Fence Repair
- POJ 3253 Fence Repair(优先队列&哈夫曼树)
- POJ 3253 Fence Repair (贪心&优先队列)
- POJ 3253 Fence Repair 优先队列
- POJ 3253Fence Repair(哈夫曼&优先队列)
- POJ 3253 Fence Repair(贪心,优先队列)
- POJ 3253 Fence Repair(贪心+优先队列)
- POJ 3253 Fence Repair 哈夫曼树 优先队列
- 20140822 【 优先队列 】 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 (优先队列)
- 第八周 项目11 利息问题
- uva 147(dp)
- 项目六 本月有几天
- 1038. Recover the Smallest Number (30)
- Linux命令学习手册-objdump命令
- poj 3253 Fence Repair (优先队列)
- 0.1-OpenStack服务—Restful API
- Samba的配置安装
- Markdown 语法手册
- golang 中io包用法(一)
- 2014年影响Web前端发展的五类API
- POJ 3276 Face The Right Way
- golang 中unicode包用法
- JAVA类中如何利用Comparator实现自定义排序