poj 3253 Fence Repair 优先队列维护
来源:互联网 发布:炒股高手软件 编辑:程序博客网 时间:2024/05/16 07:23
题目链接
为什么过的了poj,却过不了老汪出的数据~~
用优先队列,从小到大排序,每次取出最前面的两个,求和,和在放进优先队列中,直到队列仅有一项为止,结束操作
post code:
#include<stdio.h> #include<iostream>#include<queue>using namespace std;priority_queue< int,vector<int>,greater<int> > my;int main(){ int n,num; while(scanf("%d",&n)!=EOF){ while(my.empty()==0){ my.pop(); } for(int i=1;i<=n;i++){ scanf("%d",&num); my.push(num); } if(n==1){ printf("0\n"); continue; } int a,b,he; __int64 sum=0; while(my.empty()==0){ a=my.top(); my.pop(); b=my.top(); my.pop(); sum=sum+a+b; // printf("! %d\n",sum); if(my.empty()==1)break; my.push(a+b); } printf("%I64d\n",sum); } return 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 (优先队列)
- linux日常使用命令
- js 浏览器的判断
- 设计模式六大原则(2):里氏替换原则
- C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区
- javafx button
- poj 3253 Fence Repair 优先队列维护
- js实现字符串反转的两种方法
- 企业云计算实施战略
- jdk1.6与tomcat6.0配置环境变量与测试
- Sql Server杂记1--数据库变量
- js 文本改变提示剩余字数
- Java性能优化技巧
- 二进制GCD
- android build system