Codeforces 1190C Tokitsukaze and Duel game
题意:有一个长为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的更多相关文章
- Codeforces 1190C. Tokitsukaze and Duel
传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...
- Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取
https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...
- [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)
[Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...
- E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)
"Duel!" Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty ha ...
- Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Tokitsukaze and Duel CodeForces - 1191E (博弈论)
大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果. 先判断第一步是否能直接赢, 不能的 ...
- Codeforces - 1191F - Tokitsukaze and Strange Rectangle - 组合数学 - 扫描线
https://codeforces.com/contest/1191/problem/F 看了一下题解的思路,感觉除了最后一段以外没什么启发. 首先离散化x加快速度,免得搞多一个log.其实y不需要 ...
- Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟
https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么 ...
- Codeforces - 1191B - Tokitsukaze and Mahjong - 模拟
https://codeforces.com/contest/1191/problem/B 小心坎张听的情况. #include<bits/stdc++.h> using namespac ...
随机推荐
- PL SQL安装
首先,在官网下载PL SQL 的对应版本,本机是64位的就下载64位的,网址:https://www.allroundautomations.com/downloads.html#PLS 点击应用程序 ...
- 【串线篇】Mybatis缓存之整合第三方缓存
为什么要用第三方缓存?因为mybatis的缓存机制说白了就是一个map,不够强大.但幸好mybatis有自知之明将其Cache做成了一个接口开放出来,我们可以实现这个接口用第三方专业的缓存框架去自定义 ...
- BZOJ4269 再见xor
考前挣扎 线性基裸题 mx直接求 次大直接从低到高枚举第一个非0位 然后次大就是异或上就行了[显然贪心呐qwq 不到800b可还行 //Love and Freedom. #include<cs ...
- Oracle11g新建用户及用户表空间
/* 建立数据表空间 */CREATE TABLESPACE SP_TAB DATAFILE '/u01/app/oracle/oradata/orcl/tab1_1.dbf' size 1024M ...
- 回炉Spring--事务及Spring源码
声明式事务 配置文件信息: /** * @EnableTransactionManagement 开启基于注解的事务管理功能 * 1.配置数据源 * 2.配置事务管理器来管理事务 * 3.给方法上标注 ...
- 透明的UITableView
// // ViewController.m // 透明table // // Created by LiuWei on 2018/4/23. // Copyright © 2018年 xxx. Al ...
- SQL查看所有表的大小
--查看所有表的大小 declare @id int ) declare @pages int declare @dbname sysname ,) ,) ,) create table #spt_s ...
- 洛谷P3374(线段树)(询问区间和,支持单点修改)
洛谷P3374 //询问区间和,支持单点修改 #include <cstdio> using namespace std; ; struct treetype { int l,r,sum; ...
- HDU 6055 Regular polygon —— 2017 Multi-University Training 2
Regular polygon Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- git merge 上线操作流程
switch to branch git merge 主干到分支解决冲突,解决冲突文件,冲突文件,add to index 检查文件无<<<<<<< .=== ...