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

why wa

Posted by team29 at 2005-10-28 14:22:14 on Problem 2362
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int num[21]={0},count=0; 
 
int cmp ( const void *a , const void *b ) 
{ 
return *(int *)a - *(int *)b; 
}
 void main()
 {
	 int n,m,j,i,t;
	 long max=0,len;
	 scanf("%d",&n);
	 for(t=0;t<n;t++)
	 {
		 scanf("%d",&m);
	   for(j=0;j<m;j++)
	   {
		   scanf("%d",&num[j]);
		   max+=num[j];
	   }
	   if(max%4!=0) 
	   {
		   printf("no\n");
		   goto a;
	   }
	   else len=max/4;
	   qsort(num,m,sizeof(num[0]),cmp);
	   i=0;j=m-1;
	    while(i<=j)
	    {
		    if(num[i]==len) 
		    {
			    i++;count++;
		    }
		    else if(num[j]==len) 
		    {
			    j--;count++;
		    }
		    else if((num[i]+num[j])>len) break;
		    else if((num[i]+num[j])==len)
		    {
			    i++;j--;
			    count++;
		    }
		    else  i++;
	    }
	    if(count==4) printf("yes\n");
	    else printf("no\n");
a:	    memset(num,0,m);count=0;max=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