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:richardhuang大哥,你是怎么通过的。哪里要注意,谢谢。In Reply To:richardhuang大哥,你是怎么通过的。哪里要注意,谢谢。 Posted by:mmjj at 2004-07-28 23:23:26 > 我的程序还是WA: > #include <stdio.h> 贪心时有两种情况 > main() > { > > > int t,tt,n,i,j; > int a[1000]; > int min,mi,tmp; > long time; > > scanf("%d",&tt); > > > for(t=0;t<tt;t++) > { > > scanf("%d",&n); > > for(i=0;i<n;i++) > { > scanf("%d",&a[i]); > } > > > > for(i=0;i<n;i++) > { > min=1000; > for(j=i;j<n;j++) > if(a[j]<min) {min=a[j]; mi=j;} > > > tmp=a[i]; > a[i]=a[mi]; > a[mi]=tmp; > > } > > > > > time=0; > if(n==1) time=a[0]; > else > { > for(i=n-1;i>2;i=i-2) > time=time+a[i]; > time=time+((int)(n/2)-1)*(a[1]*2+a[0]); > > > if(n%2==1) time=time+a[2]+a[0]+a[1]; > else time=time+a[1]; > } > > > printf("%ld\n",time); > > > } > > > > > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator