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

在服务器上打表,125ms代码~

Posted by Qinz at 2008-10-17 13:09:38 on Problem 1012
还可以再快的,但懒得改了
#include<stdio.h>
int a[20];
int main()
{
	int k,i,temp,n,j;
	bool flag;
	for (k=1;k<14;k++)
	{
		n=k;
		flag=false;
		while(!flag)
		{
			temp=(n-1)%(2*k);
			if (temp>=k&&(n%(k+1)==0||n%(k+1)==1)) flag=true;
			else 
			{
				n++;
				continue;
			}
			for (i=1;i<k;i++)
			{
				temp=(n-1-2*k+i+temp)%(2*k-i);
				if (temp<k)
				{
					flag=false;
					break;
				}
			}
			if(!flag) n++;
		}
		a[k]=n;
	}
	while(scanf("%d",&k)&&k)
	{
		printf("%d\n",a[k]);
	}
	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