【POJ 2311】 Cutting Game
2024-09-04 23:37:46
【题目链接】
http://poj.org/problem?id=2311
【算法】
博弈论——SG函数
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 210 int n,m;
int sg[MAXN][MAXN]; inline int getSG(int n,int m)
{
int i;
bool s[];
if (sg[n][m] != -) return sg[n][m];
memset(s,false,sizeof(s));
for (i = ; i <= n - ; i++) s[getSG(n-i,m)^getSG(i,m)] = true;
for (i = ; i <= m - ; i++) s[getSG(n,i)^getSG(n,m-i)] = true;
for (i = ; ; i++)
{
if (!s[i])
return sg[n][m] = i;
}
} int main()
{ memset(sg,,sizeof(sg));
while (scanf("%d%d",&n,&m) != EOF)
{
printf(getSG(n,m)?"WIN\n":"LOSE\n");
} return ; }
最新文章
- synthesize的作用
- sessionPageState与视图状态存储
- sybase ODBC驱动
- 【uva】1220 Party at Hali-Bula
- Redis 存储、查询
- SoapUI进行接口测试,怎么应对接口地址总是变化!
- [转载] 基于Dubbo框架构建分布式服务
- SpringBoot开发案例之多任务并行+线程池处理
- SQL解决时间段重复合并问题
- Jenkins编辑或替换All view
- RHCSA之路(1) -- 重拾RHEL 7
- odoo生产单原材料报表
- WordPress 之 在注册界面 实现 注册后密码直接显示在页面上
- Raw Socket vs Stream Socket vs datagram socket,原始套接字与流式套接字与数据报套接字
- 使用markdown第一个博客
- 黄聪:PHP JSON_ENCODE 不转义中文汉字的方法
- Device Tree碎碎念
- php常见排序
- cakePHP的ajax弹出窗
- HDU 3970 Harmonious Set 容斥欧拉函数