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 20054738 at 2007-04-27 21:46:47 on Problem 2657
//ID2657_poj
//#include<iostream>
#include<memory.h>
#include<stdio.h>


//using namespace std;

void main()
{
	bool b[1010],flag;
	int n,z,m,tamp,i,j;
	int t,span;
	while(scanf("%d %d %d",&n,&z,&m)!=EOF)
	{
		if(0==m)
		{
			//cout<<"1"<<endl;
			printf("1\n");
			continue;
		}
		if(1==z)
			printf("0\n");
		memset(b,false,sizeof(b));
		for(i=0;i<m;i++)
		{
			scanf("%d",&tamp);
			b[tamp]=true;
		}
		flag=false;
		span=t=1;
		for(span=1;span<z;span++)
		{
			for(j=1;i<=n;j++)
			{
				t=t+span;
				if(b[t])
				{
				//	span++;
					t=1;
				//	continue;
					break;
				}
				else if(t==z)
				{
					//	cout<<span<<endl;
					flag=true;
					break;
				}
				else
				{
					if(t>n)
						t=t-n;
				//	t=(t+span)%n;
				//	if(0==t)
				//		t=1;
				}
			}
			if(flag)
				break;
		}
	//	cout<<span<<endl;
		printf("%d\n",span);
		
	}
}

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