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