码迷,mamicode.com
首页 > 其他好文 > 详细

[NOIP 2004] T3 合并果子

时间:2017-12-08 01:23:28      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:for   queue   bit   noi   ret   ++   +=   vector   get   

居然和BZOJ 1724完全一样o(╯□╰)o

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int n;
priority_queue<int,vector<int>,greater<int> > q;

inline int read()
{
    char ch;
    int num,f=0;
    while(!isdigit(ch=getchar())) f|=(num==-);
    num=ch-0;
    while(isdigit(ch=getchar())) num=num*10+ch-0;
    return f?-num:num;
}

int main()
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        q.push(x);
    }
    
    if(n==1){cout << q.top();return 0;} 
    
    ll res=0;
    while(q.size()>1)
    {
        int x=q.top();q.pop();
        int y=q.top();q.pop();
        res+=(x+y);
        q.push(x+y);
    }
    cout << res;
    return 0;
}

 

[NOIP 2004] T3 合并果子

标签:for   queue   bit   noi   ret   ++   +=   vector   get   

原文地址:http://www.cnblogs.com/newera/p/8001550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!