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 orangelegend at 2008-09-24 21:20:42 on Problem 2244
In Reply To:超时和不超时 Posted by:orangelegend at 2008-09-24 21:20:24
#include <stdio.h>
#include <string.h>
#include<windows.h>


int main()
{
	int m,n,i,j,count,flag[256];
	long t1,t2;
	freopen("d:\\test.txt","r",stdin);
	t1 = GetTickCount();
	while (scanf("%d",&n) != EOF && n != 0)
	{		
		m = 1;
		while (1)
		{
			memset(flag,0,sizeof(flag));
			flag[0] = count = 1;
			i = 0;
			while (count != n)
			{
				for(j = 0; j < m; i = (i + 1) % n)
					if (flag[i] == 0)
					{
						j++;
						if (j == m)
							break;
					}
				flag[i] = 1; count++;
				if (flag[1] == 1)
					break;
			}
			if (flag[1] == 1 && count == n)
				break;
			m++;
		}
		printf("%d\n",m);
	}
	t2 = GetTickCount();
	printf("time cost %ld\n",t2 - t1);
	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