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:我的程序也超时啊, 请问谁有更好的方法。

Posted by scauben0 at 2005-10-20 20:01:21 on Problem 1012
In Reply To:我的程序也超时啊, 请问谁有更好的方法。 Posted by:kodder at 2005-09-24 00:35:26
#include<iostream.h>
#include<fstream.h>//

void main()
{
	fstream fin("in.txt",ios::in||ios::out);//
	fstream fout("out.txt",ios::out);//
	unsigned long input,population,m,dis,m1,t,tt;//;	
	long int a[20];
	for(int i=0;i<=19;i++)
		a[i]=-1;
	while(1)
	{

		cin>>input;


		if(input==0)
			return;
        if(a[input]!=-1) 
		{
			cout<<a[input]<<endl;
			continue;
		}
		
		m=input+1;//initialize m

		while(1)
		{
			population=2*input;//the number of people
			dis=0;
	
			while(1)
			{
				m1=m-dis;

				m1%=population;

				if(m1>input||m1==0)
				{
					dis=population-m1;
					if(m1==0)
						dis=0;
					
					population--;

				}
				else
					break;
				if(population==input)
					break;
			}
			if(population==input)
				break;
		 
			m++;
		}
		a[input]=m;
		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