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:终于不打表AC,282ms,放出代码,求更快的解法……

Posted by 23020078104065 at 2008-12-26 23:43:58 on Problem 1012
In Reply To:终于不打表AC,282ms,放出代码,求更快的解法…… Posted by:alexneko at 2008-07-12 16:14:45
#include <stdio.h>

void main()
{
	int i,k,n;
	int people[13];
	int now,count,total;
	for(i=0;i<13;i++)
		people[i]=0;
	scanf("%d",&k);
	while(k)
	{
		n=1;
		i=k+1;
		if(!people[k-1])
		    while(1)
			{   
				now=count=0;
                total=2*k;
		    	if(i > 2*n*k)
				{	
			    	i = 2*n*k+k+1;
			    	n++;
				}
		    	while(count < k)
				{
					now=(now+i-1) % total;
			    	if(now < k)
                       break;
			    	count++;
			    	total--;
				}
		    	if(count == k)
				{
		     		people[k-1]=i;
			    	break;
				}
		    	i++;
			}
		printf("%d\n",people[k-1]);
	   	scanf("%d",&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