poj 3253
来源:互联网 发布:xp取消网络凭证 编辑:程序博客网 时间:2024/06/05 09:37
用优先队列,复杂度为nlogn
代码如下
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<queue>using namespace std;int main(){int n;scanf("%d",&n);priority_queue<int,vector<int>,greater<int> >q;for(int i=0;i<n;i++){int temp;scanf("%d",&temp);q.push(temp);}long long ans=0;while(q.size()>1){int l1,l2;l1=q.top();q.pop();l2=q.top();q.pop();ans+=l1+l2;q.push(l1+l2);}printf("%lld\n",ans);}
阅读全文
0 0
- POJ 3253
- poj 3253
- poj 3253
- poj 3253
- poj----3253
- poj.3253
- poj 3253
- POJ 3253
- poj 3253
- poj-3253
- POJ-3253
- POJ 3253
- poj 3253
- poj-3253
- poj-3253
- POJ 3253
- POJ 3253
- POJ 3253
- 用R语言计算班级各门课程的加权平均分
- Floyd algorithm原理及使用
- 后缀表达式计算
- BZOJ 2844 异或线性基(HDU3949 升级版
- 【爬虫】用 urllib.request 解析网页
- poj 3253
- Connected to the target VM, address: '127.0.0.1:60626', transport: 'socket' Disconnected from the ta
- HDU1540 Tunnel Warfare(线段树,区间合并)
- Spark简介
- 【爬虫】正则表达式解析网页
- jdk1.7安装详细过程
- C语言模块化程序设计
- github代码资源
- 广州CVTE公司笔试程序题