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 ...
随机推荐
- 阿里云maven仓库镜像mirror,速度超快
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http:/ ...
- UVa 1638 - Pole Arrangement(dp)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Redis(RedisTemplate)使用list链表
RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html package com.wbg.springRedis.test ...
- android:windowSoftInputMode属性详解 软键盘
android:windowSoftInputMode activity主窗口与软键盘的交互模式,可以用来避免输入法面板遮挡问题,Android1.5后的一个新特性. 这个属性能影响两件事情: [一] ...
- 不推荐在iOS的浏览器应用上使用click和mouseover
iOS上的Safari也支持click 和mouseover等传统的交互事件,只是不推荐在iOS的浏览器应用上使用click和mouseover,因为这两个事件是为了支持鼠标点击而设计 出来的.Cli ...
- HDU 2096 小明A+B(%的运用)
传送门: 小明A+B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- libstagefright 音视频同步方案
1:音视频数据都有一个list,用于存放解码后的数据: List mFilledBuffers; 2:解码后的音视频数据不断的往list中存放,不做音视频同步方面的时间上控制 mFille ...
- 将Tomcat设置为windows自动启动的服务
一般情况下Tomcat服务需要手动运行批命令启动服务.在windows操作系统下如果需要将Tomcat变成自动启动的服务,只需按以下步骤操作即可: 方法/步骤 将Tomcat设置成服务(假设我们缺省的 ...
- JQuery手写一个简单的分页
效果图: 大概思路:使用ul进行初始布局,每一次点击事件改变li里的值.完整的代码在gitup上:https://github.com/anxizhihai/Paging.gitcss部分: html ...
- mysql update 子查询锁表问题
mysql在Update带有子查询的时候,子查询的表会锁住,导致该表无法使用.比如 update A set comments = (select count(1) from B where id = ...