codechef Table Game(博弈)
题意
很难概括。。
Sol
(因为比赛还没结束,所以下面讲的可能是“非官方”“正解”)
maya这题我前前后后 断断续续的做了一个星期才A掉。CC一场challenge出两道打表题可有点过分了啊。。
首先考虑暴力怎么打,我们把给出的初始行列的01取反,这样$0$的时候对应的是必胜态,$1$对应的是必败态。
然后按博弈论的定义推,$(i, j)$若是必胜态,那么至少有$(i - 1, j)$是必败态 或者 $(i, j - 1)$是必败态。
然后暴力枚举一遍就行了,复杂度$O(NM)$
接下来的操作就比较神仙了,,打表 或 直接观察式子可得,若第$(i, j)$个点是必败点,那么它所在的对角线往后的点,都是必败点!
这样我们就把状态降到了$2 * M$
那最开始的必败点怎么求呢?
直觉告诉我们 稍加证明不难得到,这种点一定是出现在前两行 或者前两列。
然后就做完了。
暴力推前两行 前两列即可。
保险起见我推了三行三列。
#include<cstdio>
#include<cstring>
#include<vector>
#define LL long long
using namespace std;
const int MAXN = 1e5 + ;
inline LL read() {
char c = getchar(); LL x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int T;
int a[][MAXN], b[MAXN][], N, M, f[MAXN], g[MAXN];
char A[MAXN], B[MAXN];
int main() {
//- freopen("a.out", "w", stdout);
int T = read();
while(T--) {
scanf("%s", A + );
scanf("%s", B + );
M = strlen(A + );
N = strlen(B + );
for(int i = ; i <= M; i++) a[][i] = (A[i] == '' ? : );
for(int i = ; i <= ; i++) a[i][] = (B[i] == '' ? : ); for(int i = ; i <= ; i++) b[][i] = (A[i] == '' ? : );
for(int i = ; i <= N; i++) b[i][] = (B[i] == '' ? : ); memset(f, 0x7f, sizeof(f));
memset(g, 0x7f, sizeof(g)); for(int i = ; i <= ; i++) {
for(int j = ; j <= M; j++) {
if(a[i - ][j] == || a[i][j - ] == ) a[i][j] = ;//能到达必败节点的
else a[i][j] = ;
if(a[i][j] == ) f[j - i + ] = min(f[j - i + ], i);
}
} for(int i = ; i <= N; i++) {
for(int j = ; j <= ; j++) {
if(b[i - ][j] == || b[i][j - ] == ) b[i][j] = ;
else b[i][j] = ;
if(b[i][j] == ) g[i - j + ] = min(g[i - j + ], j);
}
}
vector<int> ans;
int Q = read();
while(Q--) {
int x = read(), y = read();
int dy = y - x + ,
dx = x - y + ;
if(dy >= ) {
if(x >= f[dy]) ans.push_back();
else ans.push_back();
} else {
if(y >= g[dx]) ans.push_back();
else ans.push_back();
}
}
for(int i = ; i < ans.size(); i++) printf("%d", ans[i]);
puts("");
} return ;
}
/*
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
*/
codechef Table Game(博弈)的更多相关文章
- codechef Graph on a Table
codechef Graph on a Table https://www.codechef.com/problems/TBGRAPH 题意 : 一个\(n\times m\)的网格图.\(q\) 个 ...
- UVa 1609 (博弈) Foul Play
姑且把它归类为一道博弈吧,毕竟这也是在找必胜方案. 十分有意思的一道题目,设计一种方案让你支持的1队获胜. 题目给出了两个很重要的条件: 1队能打败至少一半的队伍 对于1队不能打败的黑队,一定存在一个 ...
- UVA 10404 Bachet's Game(dp + 博弈?)
Problem B: Bachet's Game Bachet's game is probably known to all but probably not by this name. Initi ...
- Codechef September Challenge 2018 游记
Codechef September Challenge 2018 游记 Magician versus Chef 题目大意: 有一排\(n(n\le10^5)\)个格子,一开始硬币在第\(x\)个格 ...
- UVA12293 Box Game —— SG博弈
题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉 ...
- UVA1482 Playing With Stones —— SG博弈
题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一 ...
- CodeChef A String Game(SG)
A String Game Problem code: ASTRGAME Submit All Submissions All submissions for this problem a ...
- Codeforces 388C Fox and Card Game (贪心博弈)
Codeforces Round #228 (Div. 1) 题目链接:C. Fox and Card Game Fox Ciel is playing a card game with her fr ...
- Codeforces Gym-100985C: MaratonIME plays Nim(交互题&博弈)
C. MaratonIME plays Nim time limit per test : 2.0 smemory limit per test : 64 MBinputstandard inputo ...
随机推荐
- 一、异步编程模型(APM)
一.概念 APM即异步编程模式的简写(Asynchronous Programming Model).大家在写代码的时候或者查看.NET 的类库的时候肯定会经常看到和使用以BeginXXX和EndXX ...
- Micro
Micro 架构与设计 Micro 架构与设计 翻译自 Micro architecture & design patterns for microservices 注: 原文作者即 Mi ...
- System IPC 与Posix IPC(semaphore信号灯)
POSIX下IPC主要包括三种: posix message queue posix semaphores posix shared memory sysytem v IPC包括: system v ...
- nefu 628 Garden visiting
//yy:想到昨天一个神题整了几个小时,最后按题解把p拆了用孙子定理..今天这个简单,把C暴力拆了.. 题目链接:nefu 628 Garden visiting 1 <= n, m, p &l ...
- 我上线的android版app
把自己开发的几个小的app上线了,在自己的博客中推广一下吧: 聊天兔子: 下载地址:http://android.myapp.com/myapp/detail.htm?apkName=com.fuly ...
- 模式:模版、样式;属于分类、识别的范围;分类、归类的标准-How are patterns obtained?
模式及套路 模式:模版.样式:属于分类.识别的范围. How are patterns obtained? Through : re-use, classification and finally a ...
- Multiply Strings 字符串相乘
http://www.cnblogs.com/TenosDoIt/p/3735309.html https://blog.csdn.net/fly_yr/article/details/4805561 ...
- 二十七、详述 IntelliJ IDEA 设置 Sublime 代码颜色的方法
相信很多同学在使用 Sublime 时,看到那些五颜六色的代码感觉爽的不行,而反过来,再来看 IntelliJ IDEA 默认的代码颜色就感觉有些不爽啦!实际上,我们是可以通过「导入设置」的方式,来设 ...
- PAT——1018. 锤子剪刀布
大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算最大. 输入格式: 输入第1行给出正整数N( ...
- 在eclipse中查看HttpServlet源码失败的解决方法
在初次建立java EE 项目时,想要查看HttpServlet源码时会提示失败, 按照网上的方式,将Tomcat中lib中的servlet-api.jar的包导进去,发现并不管用.并且提示里面并不包 ...