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

Re:哪位牛人帮忙看看呀?怎么老是WA呀?

Posted by liaoqiaozhi at 2010-08-05 15:53:18 on Problem 1700
In Reply To:Re:哪位牛人帮忙看看呀?怎么老是WA呀? Posted by:liaoqiaozhi at 2010-08-05 14:23:54
> #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];//这里修改为a[n-j-1];
> 			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:
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