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 faen at 2005-04-22 17:50:49 on Problem 1700
import java.io.*;
import java.util.*;
public class Main1700
{
	public static void main(String [] args)throws Exception
	{
		InputStream in=new FileInputStream("c:\\in.txt");
		Scanner cin=new Scanner(in);
		int T=cin.nextInt();
		while(T--!=0)
		{
			int n=cin.nextInt();
			int []a=new int[n];
			for(int i=0;i<n;i++)
				a[i]=cin.nextInt();
			Arrays.sort(a);
			int sum=0;
			if(n==1)
				sum=a[0];
			if(n==2)
				sum=a[1];
			if(n==3)
				sum=a[1]+a[0]+a[2];
			if(n>3)
			{
				if(n%2==0)
				{
					for(int i=n-1;i>=2;i-=2)
					{
						if(a[i]+a[i-1]+a[0]<a[i]+2*a[1]+a[0])
							sum+=a[i]+a[i-1]+a[0];
						else
							sum+=a[i]+2*a[1]+a[0];
					}
					sum+=a[1];
				}
				else
				{
					for(int i=n-1;i>=4;i-=2)
					{
						if(a[i]+a[i-1]+a[0]<a[i]+2*a[1]+a[0])
							sum+=a[i]+a[i-1]+a[0];
						else
							sum+=a[i]+2*a[1]+a[0];
					}
					sum+=a[1]+a[0]+a[2];
				}
			}
			System.out.println(sum);
		}
	}
}

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