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 liuyao8885 at 2006-02-05 11:31:44 on Problem 1012
#include <iostream>
#include <string>

using namespace std;

bool findNext();

int k;
int m;
int current;
basic_string<int> executeStatus;  // 1 indicates executed, 0 not

int main()
{
	cin >> k;

	while (k != 0)
	{
		int i;
		bool flag;

		executeStatus.resize(k * 2);
		
		for (m = k + 1; ; m++)
		{
			current = 0;  // initial position
			flag = true;

			for (i = 0; i < 2 * k; i++)
			{
				executeStatus[i] = 0;
			}

			for (i = 0; i < k; i++)
			{
				if (!findNext())
				{
					flag = false;
					break;
				}
			}

			if (flag == true)
			{
				break;
			}
		}

		/*
		 * output result and read the next k
		 */
		cout << m << endl;
		cin >> k;
	}

	return 0;
}

bool findNext()
{
	int i;

	for (i = 0; i < m;)
	{
		if (executeStatus[current] == 0)
		{
			i++;
			if (i != m)
			{
				current = (current + 1) % (2 * k);
			}
		}
		else
		{
			current = (current + 1) % (2 * k);
		}
	}


	if (current < k)
	{
		return false;
	}
	else
	{
		executeStatus[current] = 1;
		
		/*
		 * position to the next guy
		 */ 
		for (i = 0; i < 1;)
		{
			current = (current + 1) % (2 * k);
			if (executeStatus[current] == 0)
			{
				i++;
			}
		}
		return true;
	}
}

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