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 skogt at 2010-08-02 10:52:16 on Problem 1700
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1024];
int main(){
	int t;
	int n;
	while(scanf("%d",&t)==1){
		while(t--){
			int total1=0,total2=0;
			scanf("%d",&n);
			for(int i=0;i<n;i++)
				scanf("%d",&a[i]);
			sort(a,a+n);
			if(n<3)	printf("%d\n",a[n-1]);
			else if(n==3)	printf("%d\n",a[0]+a[1]+a[2]);
			else{
				if(n%2==0){
					for(int j=1;j<n;j++)
						total1+=a[j];
					total1=total1+(n-2)*a[0];
					total2=(a[0]+a[1])*(n/2-1)+a[1];
					for(int j=n-1;j>=2;j-=2)
						total2+=a[j]+a[1];
					printf("%d\n",total1>total2? total2 : total1);
				}
				else{
						for(int j=1;j<n;j++)
							total1+=a[j];
						total1=total1+(n-2)*a[0];
						total2=(a[0]+a[1])*(n/2);
						for(int j=n-1;j>=3;j-=2)
							total2+=a[j]+a[1];
						total2+=a[2];
						printf("%d\n",total1>total2? total2 : total1);
				}

			}
		}

	}
	return 0;
}

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