poj 3253

来源:互联网 发布:网络共享服务器 反应慢 编辑:程序博客网 时间:2024/05/19 21:40
题目链接  http://poj.org/problem?id=3253
#include <queue>#include <stack>#include <math.h>#include <vector>#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>#include <functional>#define N 100#define mem(a) memset(a,0,sizeof(a));using namespace std;struct cmp1{    bool operator()(int &a,int &b)    {        return a > b;//最小值优先    }};int main(){    int n;    long long ans=0,x,y,z;    priority_queue<int,vector<int>,cmp1>Q;    cin >> n;    while(n--)    {        cin >> x;        Q.push(x);    }    while(Q.size()>1)    {        y = Q.top();        Q.pop();        z = Q.top();        Q.pop();        Q.push(y+z);        ans+=y+z;    }    cout << ans << endl;    return 0;}

0 0
原创粉丝点击