HDU

题目链接

https://vjudge.net/problem/HDU-2897

题目大意

就是现在一堆石子有n颗, 每次只能拿走p~q颗, 当剩余少于p颗的时候必须一次拿完

拿走最后一颗的人败

问谁会获得胜利

大致思路:

首先不难发现当n <= p的时候是必败点(P点),那么对于p + 1 <= n <= p + q, 这些都都可以转移到必败点(P点), 他们都是必胜点(N点), 而对于(p + q + 1 <= n <= 2*p + q) , 治呢走到必胜点(N点), 那么这些都是必败点(P点), 然后$ 2p + q + 1 <= n <= 2p + 2*q$都是必胜点(N点)

以此类推所有(k*(p + q) + 1 <= n <= k*(p + q) + p)的都是必胜点(P点, 先手败), 所有(k*(p + q) + p + 1 <= n <= (k + 1)*(p + q))的都是必败点(N点, 先手胜)

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n, p, q;
string Answer[2] = { "LOST
","WIN
" };
int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	while (cin >> n >> p >> q) {
		n %= (p + q);
		if (n > p || n == 0)
			cout << Answer[1];
		else
			cout << Answer[0];
	}
}

The desire of his soul is the prophecy of his fate
你灵魂的欲望,是你命运的先知。

原文地址:https://www.cnblogs.com/RioTian/p/13647739.html