题意:有一个长为n的01串,两个人轮流操作,每个人可以把某个长度为m的区间变成相同颜色,谁在操作后整个串颜色相同就赢了。问最后是谁赢?(有可能平局)

思路:容易发现,如果第一个人不能一击必胜,那么他就会向平局发展。同理,如果第二个人不能在第一个人的所有第一步的可能走法之后都能一击必胜,那么他也会向平局发展。所有,问题转化为了第一个人能不能一击必胜,第二个人能不能在第一步的所有走法之后一击必胜。

先考虑第一个人,我们只要判断能不能找到一个区间,使得这个区间的颜色相同之后,向左右延伸可以到串的两端即可。设当前枚举的区间是[l, r],如果s[l - 1]和s[r + 1]颜色相同,并且s[l - 1]向左延伸可以到1,s[r + 1]向右延伸可以到n,那么就找到了一个必胜区间。

现在考虑对于每个第一步,第二个人能不能必胜。还是假设第一步覆盖的区间是[l, r],那么如果l - 1和r + 1有一个不能延伸到端点,第二个人就不可能必胜(l = 1和r = n的情况除外)。如果都可以延伸到两端,那么s[l - 1]和s[r + 1]一定不同。那么只有1到l - 1和 r + 1到n都小于等于m才行,即无论你选什么颜色,我都可以把剩下的颜色不一样的部分变成一样的,这样必胜情况 + 1。l = 1和r = n的情况同理,特判一下即可。最后,看一下第一步方案数和必胜数是否一样即可。

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char s[maxn];
int l[maxn], r[maxn];
int n, m;
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
l[0] = 1;
for (int i = 1; i <= n; i++) {
if(s[i] == s[i - 1]) l[i] = l[i - 1];
else l[i] = i;
}
r[n + 1] = n;
for (int i = n; i >= 1; i--) {
if(s[i] == s[i + 1]) r[i] = r[i + 1];
else r[i] = i;
}
if(r[1] == n) {
printf("tokitsukaze\n");
return 0;
}
int cnt = 0;
for (int l1 = 1, r1 = m; r1 <= n; l1++, r1++) {
if(l[l1 - 1] == 1 && r[r1 + 1] == n) {
if(l1 == 1 || r1 == n || (s[l1 - 1] == s[r1 + 1])) {
printf("tokitsukaze\n");
return 0;
} else {
if(l1 - 1 <= m && n - r1 <= m) cnt++;
}
} else if(l1 == 1) {
if(n - r1 <= m) cnt++;
} else if(r1 == n) {
if(l1 - 1 <= m) cnt++;
}
}
if(cnt == n - m + 1) printf("quailty\n");
else printf("once again\n");
}

  

Codeforces 1190C Tokitsukaze and Duel game的更多相关文章

  1. Codeforces 1190C. Tokitsukaze and Duel

    传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...

  2. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

  3. [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)

    [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...

  4. E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)

    "Duel!" Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty ha ...

  5. Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. Tokitsukaze and Duel CodeForces - 1191E (博弈论)

    大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果. 先判断第一步是否能直接赢, 不能的 ...

  7. Codeforces - 1191F - Tokitsukaze and Strange Rectangle - 组合数学 - 扫描线

    https://codeforces.com/contest/1191/problem/F 看了一下题解的思路,感觉除了最后一段以外没什么启发. 首先离散化x加快速度,免得搞多一个log.其实y不需要 ...

  8. Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟

    https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么 ...

  9. Codeforces - 1191B - Tokitsukaze and Mahjong - 模拟

    https://codeforces.com/contest/1191/problem/B 小心坎张听的情况. #include<bits/stdc++.h> using namespac ...

随机推荐

  1. H2database创建表

    语法和sql server大同小异 create table users(id int primary key not null int identity, name varchar(20))

  2. golang-练习1

    题目: 输入字符串,返回最大的单词. 实例:run#¥@!time   返回:time package main import ( "fmt" "strings" ...

  3. 终端、mac等小技巧——2019年10月18日

    1.新建finder窗口 cmd+N 2.查看文件夹结构 brew install tree tree命令行参数(只实用与安装了tree命令行工具): -a 显示所有文件和目录. -A 使用ASNI绘 ...

  4. react-jsx和数组

    JSX: 1.全称:JavaScriptXML, 2.react定义的一种类似于XML的JS扩展语法:XML+JS 3.作用:用来创建react虚拟DOM(元素)对象 var ele=<h1&g ...

  5. SOA架构是什么?

    https://blog.csdn.net/u013343616/article/details/79460398 SOA是什么?SOA全英文是Service-Oriented Architectur ...

  6. 修改host,访问指定服务器

    途径: 1.hosts文件修改 以Windows文件为例:进入system32/drivers/etc/hosts 或者用一些软件比如switchhost等来进行修改 2.通过抓包工具修改 因为本人是 ...

  7. axios拦截器的使用方法

    很多时候我们需要在发送请求和响应数据的时候做一些页面处理,比如在请求服务器之前先判断以下用户是登录(通过token判断),或者设置请求头header,或者在请求到数据之前页面显示loading等等,还 ...

  8. 本地develop往远端develop上推代码步骤

  9. JS中数据结构之字典

    字典是一种以键 - 值对形式存储数据的数据结构 通过数组实现字典 function Dictionary() { this.add = add; this.datastore = new Array( ...

  10. NOIP day1 玩具谜题

    逻辑有一些复杂,但是理解之后就很简单.题目描述中mogician什么的太暴力了...-1s 按照题目描述模拟,就能满分. /* Au: GG * CCF NOIP2016 day1 * toy */ ...