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 <stdio.h> void compositor(long a[],long n) { int i,j,t; for(j=1;j<n;j++) for(i=0;i<n-1;i++)if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;} } void main() { long i,j,t,n,time[1000],total; scanf("%ld",&t); for(j=0;j<t;j++) { scanf("%ld",&n); for(i=0;i<n;i++)scanf("%ld",&time[i]); if(n==1)total=time[0]; else { compositor(time,n); total=0; if(n%2==0) { for(i=3;i<n;i+=2)total+=time[i]; total+=(2*time[1]+time[0])*((n-2)/2)+time[1]; } else if(n%2==1) { for(i=4;i<n;i+=2)total+=time[i]; total+=(2*time[1]+time[0])*((n-3)/2)+time[2]+time[0]+time[1]; } } printf("%ld\n",total); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator