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

Dont know why WA?

Posted by yogafrank at 2007-11-30 17:46:13 on Problem 3312
I have tested nearly all the datas that I could imagine.
Please help me out and many thanks for you guys.

# include <stdio.h>
# include <stdlib.h>
# include <string.h>

int lenth[1000];
int n, k;

int cmp ( const void *a, const void *b )
{
	return *(int *)a - *(int *)b;
}

int check ( int index )
{
	int sum = 0, i;

	for ( i = 0; i < k; i++ )
		sum += lenth[index * k + i];

	for ( i = 0; i < k; i++)
		if ( lenth[index * k + i] * k > sum * 2 )
			return 1;
	return 0;
}

int main ()
{
	char name[81];
    int i, flag, count = 1;

	freopen ("3312.txt", "r", stdin);
	while ( scanf ( "%d%d", &n, &k ) != -1 )
	{
		if ( n == 0 && k == 0 )
			break;

		flag = 0;
		for ( i = 0; i < n; i++ )
		{
			scanf ( "%s", name );
			lenth[i] = strlen ( name );
		}

		qsort ( lenth, n, sizeof (int), cmp);

		for ( i = 0; i < n / k; i++ )
			if ( check ( i ) )
			{
				flag = 1;
				break;
			}

		printf ( "Case %d: ", count++);
		if ( flag )
			puts ("no");
		else 
			puts ("yes");
		puts ("");
	}
}

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