有一个n*m 的棋盘,每个点上标记了L,R,X 中的一个
每次能选择一个没有被攻击过的点(i,j),从这个点开始
发射线,射线形状为:
1. 若字符是 L,向左下角和右上角发,遇到被攻击过的点
就停下来
2. 若字符是 R,向左上角和右下角发,遇到被攻击过的点
就停下来
3. 若字符是 X,向左小左上右下右上发,遇到被攻击过的
点停下来
问先手是否必胜,n,m<=20

先将棋盘黑白染色,再旋转45°,黑的和白的各为一个组合游戏。

然后设sg[a][b][c][d]表示横坐标在[a,b],纵坐标在[c,d]里这个局面的sg值。

复杂度O(n6)

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 22
using namespace std;
char ch,s[maxn][maxn];
int n,m,N,sg[maxn][maxn][maxn][maxn],op[maxn][maxn];
bool ok,bo[];
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
int calc(int a,int b,int c,int d){
if (a>b||c>d) return ;
if (sg[a][b][c][d]!=-) return sg[a][b][c][d];
for (int i=a;i<=b;i++)
for (int j=c;j<=d;j++)
if (op[i][j]==) calc(a,b,c,j-),calc(a,b,j+,d);
else if (op[i][j]==) calc(a,i-,c,d),calc(i+,b,c,d);
else if (op[i][j]==) calc(a,i-,c,j-),calc(a,i-,j+,d),calc(i+,b,c,j-),calc(i+,b,j+,d);
for (int i=a;i<=b;i++)
for (int j=c;j<=d;j++)
if (op[i][j]==) bo[calc(a,b,c,j-)^calc(a,b,j+,d)]=;
else if (op[i][j]==) bo[calc(a,i-,c,d)^calc(i+,b,c,d)]=;
else if (op[i][j]==) bo[calc(a,i-,c,j-)^calc(a,i-,j+,d)^calc(i+,b,c,j-)^calc(i+,b,j+,d)]=;
for (int i=;;i++) if (!bo[i]){sg[a][b][c][d]=i;break;}
for (int i=a;i<=b;i++)
for (int j=c;j<=d;j++)
if (op[i][j]==) bo[calc(a,b,c,j-)^calc(a,b,j+,d)]=;
else if (op[i][j]==) bo[calc(a,i-,c,d)^calc(i+,b,c,d)]=;
else if (op[i][j]==) bo[calc(a,i-,c,j-)^calc(a,i-,j+,d)^calc(i+,b,c,j-)^calc(i+,b,j+,d)]=;
return sg[a][b][c][d];
}
int solve(int p){
memset(op,,sizeof(op));
memset(sg,-,sizeof(sg));
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (((i+j)&)==p) op[(i-j+m+)>>][(i+j)>>]=s[i][j]=='L'?:s[i][j]=='R'?:;
return calc(,N,,N);
}
int main(){
read(n),read(m),N=(n+m)>>;
for (int i=;i<=n;i++) scanf("%s",s[i]+);
puts(solve()^solve()?"WIN":"LOSE");
return ;
}

最新文章

  1. SuperMap iClient for JavaScript 新手入门
  2. UI: 标题栏
  3. 关于onbeforeunload的一些想法
  4. Lost Cows(线段树 POJ2182)
  5. 两个数组 [n] [m] n&gt;m 第一个数组的数字无序排列 第二个数组为空 取出第一个数组的最小值 放到第二个数组中第一个位置, 依次类推. 不能改变A数组,不能对之进行排序,也不可以倒到别的数组中。
  6. hdu 4217 Data Structure? 树状数组求第K小
  7. ASP.NET中动态获取数据使用Highcharts图表控件【Copy By Internet】
  8. 好看的UI界面
  9. 提交jar作业到spark上运行
  10. ios 字典转模型
  11. SGU 176.Flow construction (有上下界的最大流)
  12. angularJS 过滤器 表单验证
  13. 如何改变c盘的访问权限
  14. [css 揭秘]:CSS揭秘 技巧(一):半透明边框
  15. vim 去除代码行号并正常缩进代码
  16. ios开发蓝图
  17. This license xxx has been cancelled 解决
  18. CNN 文本分类
  19. Python自学笔记-装饰器1(廖雪峰的网站)
  20. 页面弹出全屏浮层或遮罩时,禁止底层body滚动

热门文章

  1. Eucalyptus安装包的功能列表
  2. Apache HBase 2015年发展回顾与未来展望
  3. H - Pots
  4. poj1026
  5. linux —— shell 编程(整体框架与基础笔记)
  6. 导入excel 数据到mysql出现的时间格式
  7. Spring4.0支持Groovy配置
  8. 开发环境下jboss 7.1.1 Final 的jsp热部署解决方案--转
  9. 《Android开发艺术探索》读书笔记 (7) 第7章 Android动画深入分析
  10. 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之三