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

Re:简单约瑟夫问题,注意存下数据,数据有重复,不存会超时

Posted by 3013218059 at 2015-04-12 08:07:40 on Problem 1012
In Reply To:简单约瑟夫问题,注意存下数据,数据有重复,不存会超时 Posted by:ld2rxt at 2014-09-13 23:32:38
> #include<stdio.h>
> int a[15];
> int main()
> {
> 	int k;
> 	while(scanf("%d",&k)&&k!=0)
> 	{
> 		int i,j,m = k,s;
> 		if(a[k])
> 		{
> 			printf("%d\n",a[k]);
> 			continue;
> 		}
> 		for(;;m++)
> 		{
> 			for(i=0;i<k;i++)
> 			{
> 				s = (m-1)%(2*k - i);
> 				for(j=2*k-i;j<2*k;j++)
> 				{
> 					s = (s+m)%(j+1);
> 				}
> 				if(s<k) break;
> 			}
> 			if(i==k)
> 			{
> 				break;
> 			}
> 		}
> 		printf("%d\n",m);
> 	    a[k] = m;
> 	}
> 	return 0;
> }
> 我看讨论有人说结果一定是k-1或者k的倍数的没懂,请教一下

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