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 |
Re:代码,献给像我一样WA好多次的同志们In Reply To:代码,献给像我一样WA好多次的同志们 Posted by:schindlerlee at 2008-07-27 10:54:07 > #include<iostream> > #include<algorithm> > using namespace std; > > #define N 20005 > //20005 > bool cmp(int a,int b) > { > return a>b; > } > > int main() > { > int n; > int i; > int fenc[N]; > > __int64 sum; > > while( scanf("%d",&n)!=EOF ) > { > for(i=0;i<n;i++) > { > scanf("%d",&fenc[i]); > } > if (1==n) > { > printf("0\n"); > continue; > } > sum=0; > > make_heap(fenc,fenc+n,cmp); > for(i=n;i>1;i--) > { > pop_heap(fenc,fenc+i,cmp); > sum+=fenc[i-1]; > pop_heap(fenc,fenc+i-1,cmp); > sum+=fenc[i-2]; > > fenc[i-2]+=fenc[i-1]; > push_heap(fenc,fenc+i-1,cmp); > } > 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