ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Cutting Game POJ2311(SG函数)

2022-02-02 22:01:07  阅读:163  来源: 互联网

标签:vector ch return int res Game Cutting include SG


Cutting Game - POJ 2311 - Virtual Judge

SG函数深入理解orz:博弈论 SG函数_Strangedbly-CSDN博客_sg函数

AC代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <map>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <numeric>
#include <iomanip>
#include <functional>
using namespace std;
#define lowbit(x) ((x) & -(x))
#define IOS1 ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define IOS2 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T>
T power(T a, int b) {
	T res = 1;
	for (; b; b >>= 1, a = a * a) {
		if (b & 1) {
			res = res * a;
		}
	}
	return res;
}
template <typename T>
inline void read(T& x)
{
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { x = x * 10 + ch - '0', ch = getchar(); }
	x *= f;
}
/*
Tips:
   1.int? long long?
   2.don't submit wrong answer
   3.figure out logic first, then start writing please
   4.know about the range
   5.check if you have to input t or not
   6.modulo of negative numbers is not a%b, it is a%b + abs(b)
*/
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI = acos(-1.0);
vector<vector<int> > sg(210, vector<int>(210, -1));
int getsg(int n, int m) {
	if (sg[n][m] != -1) {
		return sg[n][m];
	}
	vector<int> vis(1006, 0);
	for (int i = 2; i <= n - i; i++) {
		vis[getsg(i, m) ^ getsg(n - i, m)] = 1;
	}
	for (int i = 2; i <= m - i; i++) {
		vis[getsg(n, i) ^ getsg(n, m - i)] = 1;
	}
	for (int i = 0;; i++) {
		if (vis[i] == 0) {
			return sg[n][m] = i;
		}
	}
}
void solve() {
	int w, h;
	while (cin >> w >> h) {
		if (getsg(w, h)) {
			cout << "WIN" << endl;
		}
		else {
			cout << "LOSE" << endl;
		}
	}
}
int main() {
	//IOS1;
	IOS2;
	int __t = 1;
	//cin >> __t;
	for (int _t = 1; _t <= __t; _t++) {
		solve();
	}
	return 0;
}
/*

*/

标签:vector,ch,return,int,res,Game,Cutting,include,SG
来源: https://blog.csdn.net/eyuhaobanga/article/details/122772321

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有