Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

好长~~

Posted by zjut020 at 2009-03-26 11:11:54 on Problem 3253
In Reply To:Re:我的ac代码,纯c 16ms 共同学习 Posted by:sunkehappy at 2009-03-15 15:24:58
#include<iostream>
#include<fstream>
#include<queue>
using namespace std;
struct aa
{long long n;};
bool operator<(aa a,aa b)
{
    return a.n>b.n;     
}
int main()
{
    //ifstream cin("0.txt");
    priority_queue<aa>q;aa y;
    long long n,i,t;cin>>n;
    for(i=0;i<n;i++)
    {
       cin>>t;y.n=t;
       q.push(y);
    }
    if(n==1)
    cout<<0<<endl;
    else 
    {
         long long sum=0;
         while(q.size()>1)
         {
             long long a,b;
             y=q.top();
             a=y.n;
             q.pop();   
             y=q.top();
             b=y.n;
             q.pop();
             sum+=a+b;
             y.n=a+b;
             q.push(y);               
         } 
         cout<<sum<<endl; 
    }
    //system("pause");
    return 0;  
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator