Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

高手帮忙指一下错啊,谢谢了~~~~~~~~~~~~~~~~~~~~~~~

Posted by nopeak at 2004-12-18 17:30:27 on Problem 1700
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator