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 dyj at 2005-12-08 21:51:00 on Problem 1012
#include <stdio.h>
#include <malloc.h>

int judge (int *a,int hop)
{
	int i=0;
	int left=0;
	int locate=0;
	for (i=1;i<=*a;i++)
		*(a+i)=0;
	left=*a/2;
	i=hop;
	locate=1;
	while (left>=1)
	{
		if (*(a+locate)==1)
		{
			locate++;
			if (locate>*a)
				locate=1;
			continue;
		}
		if (i>1)
		{
			i--;
			locate++;
			if (locate>*a)
				locate =1;
			continue;
		}
		if (locate>*a/2)
		{
			left--;
			*(a+locate)=1;
			i=hop;
			locate++;
			if (locate>*a)
				locate=1;
			continue;
		}
		return (0);
	}
	return (1);
}


void main ()
{
	int *a;
	int num=0;
	int i=0;
	scanf ("%d",&num);
	while ((num>0)&&(num<14))
	{
		a= (int*)( malloc( sizeof(int)*(2*num+1) ));
		*a=2*num;
		for (i=num+1;!judge(a,i);i++);
		printf ("%d\n",i);
		free(a);
		scanf ("%d",&num);
	}
}


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