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 ...
随机推荐
- 轻松bypass360网站卫士WAFSQL注入防护
随便网上找了一个网站,只是测试一下,没有干非法的事情! code 区域 http://www.py-guanyun.com/CompHonorBig.asp?id=49 code 区域 http:// ...
- jsp和servlet的问题收集.... 答案有部分是自己理解的,可能有点差异
如何创建一个动态工程? File ----> New ---->other ---->Web ---->Dynamic Web Project 选择动态WEB 项目工程 W ...
- Linux下XAMPP的部署实战
上传源码文件 rz -be 下载xampp安装包wget http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/5.5.28/xampp- ...
- js实现抛物线运动 兼容IE低版本(转)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- ctrl + alt + o 快速删除掉没有使用的 import
ctrl + alt + o 优化导入,可以快速删除掉没有使用的 import
- BZOJ1396:识别子串(SAM)
Description Input 一行,一个由小写字母组成的字符串S,长度不超过10^5 Output L行,每行一个整数,第i行的数据表示关于S的第i个元素的最短识别子串有多长. Sample I ...
- 同步Internet时间
问题: 开启了 自动设置时间,时区 但问题仍然存在 回答: 勾选并不代表真正同步成功 执行timedate.cpl如图设置 记得点击立即更新 时间不同步可能是时间服务器问题 换一个就可以了
- Jmeter--调度器配置
Jmeter的线程组设置里有一个调配器设置,用于设置该线程组下脚本执行的开始时间.结束时间.持续时间及启动延迟时间.当需要半夜执行性能测试时会用到这个功能. ps:设置调度器配置,需要将前面的循环次数 ...
- HDU 1045 Fire Net(DFS 与8皇后问题类似)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Css animation 与 float 、flex 布局问题
1. 有这样一段css html 代码 <div class="container"> <div class="float-left"> ...