⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pku1059.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
int die[1001];
int cnt, p_die, N;

typedef struct Pos
{
	int to, re;
};

Pos p[101];

class Player
{
	private:
	int pos;
	bool stop;

	public:
	bool Next()
	{
		if (stop == 1)
		{
			stop = 0;
			return 0;
		}
		int newpos = pos + die[p_die++];
		if (newpos > 100)
		{
			return 0;
		}
		else if (newpos == 100)
		{
			return 1;
		}
		else
		{
			pos = newpos;
			while (p[pos].to)
			{
				pos = p[pos].to;
			}
			if (p[pos].re == 1)
			{
				return Next();
			}
			else if (p[pos].re == -1)
			{
				stop = 1;
			}
		}
		return 0;
	}
};

Player pl[7];

void GetDie()
{
	cnt = 0;
	while (scanf("%d", &die[cnt]) != -1 && die[cnt])
	{
		cnt++;
	}
}

void init()
{
	memset(pl, 0, sizeof(pl));
	memset(p, 0, sizeof(p));
}

void GetLC()
{
	int s, e;
	while (scanf("%d %d", &s, &e) != -1 && (s + e))
	{
		p[s].to = e;
	}
}

void GetStop()
{
	int v;
	while (scanf("%d", &v) != -1 && v)
	{
		if (v > 0)
		{
			p[v].re = 1;
		}
		else if (v < 0)
		{
			p[-v].re = -1;
		}
	}
}

void Solve()
{
	int i = 0;
	p_die = 0;
	while (1)
	{
		if (p_die >= cnt)
		{
			printf("No answer\n");
			break;
		}
		int v = pl[i].Next();
		if (v)
		{
			printf("%d\n", i + 1);
			break;
		}
		i = (i + 1) % N;
	}
}

int main()
{
//	freopen("PKU1059.in", "r", stdin);
	GetDie();
	while (scanf("%d", &N) != -1 && N)
	{
		init();
		GetLC();
		GetStop();
		Solve();
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -