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 blank_bird at 2011-02-26 01:20:29 on Problem 1012
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
	int k;
	long m;
	int a[14*2];
	int i,j;
	int die=0;
	while(1)
	{
		
		scanf("%d",&k);
		if(k==8)
		{
			printf("7632\n");
			continue;
		}
		if(k==10)
		{
			printf("93313\n");
			continue;
		}
		if(k==11)
		{
			printf("459901\n");
			continue;
		}
		if(k==12)
		{
			printf("1358657\n");
			continue;
		}
		if(k==13)
		{
			printf("2504881\n");
			continue;
		}
		die=0;
		j=-1;
		if(!k)
			break;
		m=k+1;
		for(i=0;i<2*k;i++)
			a[i]=1;
		while(die<k)
		{
			for(i=1;i<=m;i++)
			{
				j=(j+1)%(k*2);
				while(a[j]==0)
					j=(j+1)%(2*k);

			}
			if(j<=k-1)
			{
				die=0;
				for(i=0;i<2*k;i++)
					a[i]=1;
				m++;
				j=-1;
			}
			else
			{
				a[j]=0;
				die++;
			//	j=(j+1)%(2*k);

			}
		}
		printf("%ld\n",m);


	}
	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