| ||||||||||
| 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:liaoqiaozhi at 2010-08-05 14:23:38 #include<stdio.h>
#include<stdlib.h>
int cmp(const void *a, const void *b)
{
return *(int*)a-*(int*)b;
}
int main()
{
int n,i,j,t,time,a[1001];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);time=0;j=0;
for(i=0;i<n;i++)scanf("%d",&a[i]);
qsort(a,n,sizeof(a[0]),cmp);
while((n-j)>=4)
{
if(a[1]*2<=a[n-j-2]+a[0])
time+=2*a[1]+a[0]+a[n-j-1];
else time+=a[n-j]+a[n-j-2]+2*a[0];
j+=2;
}
if(n-j==3)time+=a[0]+a[2]+a[1];
else if(n-j==2)time+=a[1];
else if(n-j==1)time+=a[0];
printf("%d\n",time);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator