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 plumage at 2005-04-21 13:24:57 on Problem 1012
#include<iostream.h>
#include<fstream.h>

void main()
{
	fstream fin("in.txt",ios::in||ios::out);

	unsigned int input,population,m,dis,m1;
	
	while(1)
	{
//		fin>>input;
		cin>>input;


		if(input==0)
			return;

		
		m=input+1;//initialize m

		while(1)
		{
			population=2*input;//the number of people
			dis=0;
	
			while(1)
			{
				m1=m-dis;
//				cout<<m1<<" "<<dis<<" "<<m<<endl;
				m1%=population;
//				cout<<m1<<endl;
				if(m1>input||m1==0)
				{
//					population--;
					dis=population-m1;
					if(m1==0)
						dis=0;
					
					population--;
				}
				else
					break;
				if(population==input)
					break;
			}
			if(population==input)
				break;
			m++;//selfadding		
		}
		cout<<m<<endl;	
	}

}

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