yzl_rex

对于算法,我只是一个草民!

zoj 1088 System Overload

#include "iostream"
#include "stdio.h"
#include "memory.h"
using namespace std;

int citys[160];
int temp[160];

bool solve(int n, int m)
{
	int r = 1;
	int i, j;
	citys[1] = 0;
	for (i = 2, j = 1; r <= n - 2; i = i % n + 1, j = j % m + 1)
	{
		while (citys[i] == 0)
			i = i % n + 1;
		if (j % m == 0)
		{	
			if (i == 2)
				return false;
			citys[i] = 0;
			j = 0;
			r = r + 1;
		}
	}
	if (citys[2] != 0)
		return true;
	else
		return false;
}

int main()
{
	int n, i;
	while (cin >> n && n)
	{
		memset(citys, 0, sizeof(citys));
		for (i = 0; i <= n; i++)
			citys[i] = i;
		memcpy(temp, citys, sizeof(citys));
		int m;
		for (m = 1; ; m++)
		{
			memcpy(citys, temp, sizeof(citys));
			if (solve(n, m))
				break;
		}
		cout << m << endl;
	}
}

阅读更多
文章标签: system include
个人分类: ZOJ
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭