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 savon_cn at 2006-04-16 16:06:48 on Problem 1700
在VC6.0下编译通过
#include<iostream.h>
int Case[20];
int a[1000];
int arrLength=0;
int iTime=0;
void sortArray(int N)
{
	int temp;
	for(int i=0;i<N;i++)
		for(int j=i+1;j<N;j++)
		{
			if(a[i]>a[j])
			{
				temp=a[i];a[i]=a[j];a[j]=temp;
			}
		}
}
void FindSoul()
{
	if(arrLength==2)
		iTime+=a[1];
	else if(arrLength==3)
		iTime+=a[0]+a[1]+a[2];
	else
	{
		if(a[1]*2<=(a[arrLength-2]+a[0]))
		{
            iTime+=a[0]+2*a[1]+a[arrLength-1];
			arrLength-=2;
			FindSoul();
		}
		else
		{
            iTime+=2*a[0]+a[arrLength-1]+a[arrLength-2];
			arrLength-=2;
			FindSoul();
		}
	}
}
void main()
{
	int M;
	cin>>M;
	for(int i=0;i<M;i++)
	{
	int N;
	cin>>N;
	for(int t=0;t<N;t++)
		cin>>a[t];
	sortArray(N);
	arrLength=N;
	FindSoul();
    Case[i]=iTime;
	iTime=0;
	}
	for(int k=0;k<M;k++)
		cout<<Case[k]<<endl;
}

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