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 tengshengbo at 2004-09-05 01:14:03 on Problem 1012
In Reply To:由于其他方法吗? Posted by:90303121 at 2004-05-25 20:15:57
#include<iostream.h>
bool check(int i,int j)
{
	int start=1;
	int x;
	int leng=2*i;
	for(x=1;x<=i;x++)
	{
		start=(start+j-1)%leng;
		if(start==0) start=leng;
		leng--;
		if(start<=i) return false;
		if(start>leng) start=1;
	}
	return true;
}
main()
{
    int a[15];
	int i,j;
	for(i=1;i<14;i++)
	{
		for(j=i+1;;j++)
		{
			if(check(i,j))
			{
				a[i]=j;
				break;
			}
		}
	}
	cin>>i;
	while(i!=0)
	{
		cout<<a[i]<<endl;
		cin>>i;
	}
}

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