# codechef Table Game(博弈)

## Sol

（因为比赛还没结束，所以下面讲的可能是“非官方”“正解”）

maya这题我前前后后 断断续续的做了一个星期才A掉。CC一场challenge出两道打表题可有点过分了啊。。

#include<cstdio>
#include<cstring>
#include<vector>
#define LL long long
using namespace std;
const int MAXN = 1e5 + 10;
char c = getchar(); LL x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int T;
int a[4][MAXN], b[MAXN][4], N, M, f[MAXN], g[MAXN];
char A[MAXN], B[MAXN];
int main() {
//-    freopen("a.out", "w", stdout);
while(T--) {
scanf("%s", A + 1);
scanf("%s", B + 1);
M = strlen(A + 1);
N = strlen(B + 1);
for(int i = 1; i <= M; i++) a[0][i] = (A[i] == '1' ? 0 : 1);
for(int i = 1; i <= 3; i++) a[i][0] = (B[i] == '1' ? 0 : 1);

for(int i = 1; i <= 3; i++) b[0][i] = (A[i] == '1' ? 0 : 1);
for(int i = 1; i <= N; i++) b[i][0] = (B[i] == '1' ? 0 : 1);

memset(f, 0x7f, sizeof(f));
memset(g, 0x7f, sizeof(g));

for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= M; j++) {
if(a[i - 1][j] == 1 || a[i][j - 1] == 1) a[i][j] = 0;//能到达必败节点的
else a[i][j] = 1;
if(a[i][j] == 1) f[j - i + 1] = min(f[j - i + 1], i);
}
}

for(int i = 1; i <= N; i++) {
for(int j = 1; j <= 3; j++) {
if(b[i - 1][j] == 1 || b[i][j - 1] == 1) b[i][j] = 0;
else b[i][j] = 1;
if(b[i][j] == 1) g[i - j + 1] = min(g[i - j + 1], j);
}
}
vector<int> ans;
while(Q--) {
int dy = y - x + 1,
dx = x - y + 1;
if(dy >= 1) {
if(x >= f[dy]) ans.push_back(0);
else ans.push_back(1);
} else {
if(y >= g[dx]) ans.push_back(0);
else ans.push_back(1);
}
}
for(int i = 0; i < ans.size(); i++) printf("%d", ans[i]);
puts("");
}

return 0;
}
/*
2
101
01
6
1 1
1 2
1 3
2 1
2 2
2 3
101
01
6
1 1
1 2
1 3
2 1
2 2
2 3
*/

posted @ 2018-09-16 15:01  自为风月马前卒  阅读(325)  评论(0编辑  收藏  举报