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 |
哪位大牛帮我优化下代码#include<iostream> #include<algorithm> using namespace std; __int64 a[20010]; __int64 sum; void insertsort(int i1,int i2) { __int64 temp=a[i1]; int i; for(i=i1+1;i<i2;++i) if(temp>a[i]) a[i-1]=a[i]; else break; a[i-1]=temp; } int main() { // freopen("1.txt","r",stdin); int i,i1,i3; scanf("%d",&i); { sum=0; for(i1=0;i1<i;++i1) scanf("%I64d",&a[i1]); sort(a,a+i); __int64 i2; for(i1=1;i1<i;++i1) { i2=a[i1-1]+a[i1]; sum+=i2; a[i1]=i2; insertsort(i1,i); } printf("%I64d\n",sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator