Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我不知道是哪里有错误,我在Dev编译正确,这里就不行了;#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAX_N=50000; int N,L[MAX_N]; void solve() { ll ans=0; while(N>1) { int mii1=0,mii2=1; if(L[mii1]>L[mii2]) swap(mii1,mii2); for(int i=2;i<N;i++) { if(L[i]<L[mii1]) { mii2=mii1; mii1=i; } else if(L[i]<L[mii2]) { mii2=i; } } int t=L[mii1]+L[mii2]; ans+=t; if(mii1==N-1) swap(mii1,mii2); L[mii1]=t; L[mii2]=L[N-1]; N--; } printf("%lld\n",ans); } int main() { cin>>N; for(int i=0;i<N;i++) { cin>>L[i]; } solve(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator