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 kkmmnn at 2006-10-05 10:01:09 on Problem 2657
#include<iostream>
using namespace std;
int main()
{
	int N,Z,K,M;
    int o,i,w;
	w=0;
	int m[1000];
	while(cin>>N>>Z>>M)
	{ 
	  for(i=0;i<M;i++)
	  {   cin>>m[i];
	       if(i>0&&m[i]<Z)
		   {  if(m[i]==m[i-1]+1)
                   w++;
		       else w=0;
		   }
	  }
	for(K=w;K<N;K++)
	{   
		i=0;
		o=1+K;
		while(!(o==Z))
		{  
			if(o>N)
				o=o-N;
			if(o>m[i])
				i++;
		   if(o==m[i])
			   break;
		   if(o<m[i]&&(o+K)>m[i])
			   i++;
		   o=o+K;
		}
		if(o==Z) 
		{cout<<K<<endl;
    	 break;
		}
	}

	}
	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