刷题——Fence Repair POJ
来源:互联网 发布:广东省软件企业评估 编辑:程序博客网 时间:2024/06/08 05:51
/*
先排序,每次加最小两块板的大小,并把最小两块板的大小加入队列
*/
#include <stdio.h>
#include <queue>using namespace std;
#define ll long long
priority_queue<ll,vector<ll>,greater<ll> >que;
int main(){
int n;
while(~scanf("%d",&n)){
ll a;
while(!que.empty())que.pop();
for(int i=0;i<n;i++){
scanf("%I64d",&a);
que.push(a);
}
if(que.size()==1){
printf("%d\n",0);
que.pop();
}
else{
int sum=0;
while(true){
ll x=que.top();
que.pop();
ll y=que.top();
que.pop();
sum+=x+y;
if(que.empty())break;
que.push(x+y);
}
printf("%I64d\n",sum);
}
}
return 0;
}
阅读全文
0 0
- 刷题——Fence Repair POJ
- Poj3253—Fence Repair
- POJ—3253—Fence Repair—【贪心】【优先队列】
- POJ——3253 Fence Repair(优先队列)
- POJ 3253 Fence Repair(贪心—霍夫曼树or优先队列)
- poj3253——Fence Repair
- POJ3253——Fence Repair
- POJ3253——Fence Repair
- poj3253——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 3253Fence Repair
- POJ--3253 -- Fence Repair
- JZOJ1218. 黑匣子(2017年8月B组)
- angularjs实现table增加tr
- Struts2源代码查看
- wx.ClientDC在窗口最小化之后所画内容消失的问题探讨
- HDU-1029-Ignatius and the Princess IV
- 刷题——Fence Repair POJ
- 教你如何使用Linux做开机自动运行【树莓派】
- Linux ALSA声卡驱动之一:ALSA架构简介
- 暑假集训 第N天 T2 Number
- mysql中的时间戳和日期时间的转换
- HDU 2888 Check Corners 二维RMQ模板
- 竞争神经网络
- 动态规划
- hdu 6081 度度熊的王国战略 2017"百度之星"程序设计大赛