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

multiset慢姿势

Posted by xx315 at 2015-06-02 21:08:59 on Problem 3253
#include<stdio.h>
#include <iomanip>
#include<iostream>
#include<math.h>
#include<algorithm>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
#include<set>
#define pi acos(-1.0)
using namespace std;
multiset<__int64>Set;
multiset<__int64>::iterator it;
int main()
{

    int n;
    scanf("%d",&n);
    Set.clear();
    __int64 t;
    for(int i=0;i<n;i++)
    {
        scanf("%I64d",&t);
        Set.insert(t);
    }
    __int64 sum=0;
    while(Set.size()!=1)
    {
        __int64 t1,t2,t3;
        it=Set.begin();
        t1=*it;sum+=t1;
        Set.erase(it);

        it=Set.begin();
        t2=*it;sum+=t2;
        Set.erase(it);

        t3=t1+t2;
        Set.insert(t3);
    }
    printf("%I64d\n",sum);
}

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