Tokitsukaze and Duel CodeForces - 1191E (博弈论)
大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果.
先判断第一步是否能直接赢, 不能的话若所有后继都是必败则必败, 否则平局.
正确性很显然, 因为一次操作不能直接赢的话, 只要模仿对手操作一定能平局.
那么问题就转化为判断一步操作后是否能赢.
假设$0$的最大范围为$[L[0],R[0]]$,$1$的最大范围为$[L[1],R[1]]$, 那么只要操作前$R[0]-L[0]+1\le k$或$R[1]-L[1]+1\le k$那么一定必胜.
然后用带撤销的线段树枚举所有后继模拟即可.
#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
using namespace std; const int N = 1e6+10;
int n,k,clk,tim[N<<2];
char s[N];
struct _ {
int L[2],R[2];
void upd(int v, int l, int r) {
L[v]=l,R[v]=r;
L[!v]=1e9,R[!v]=-1e9;
}
_ operator + (const _ & rhs) const {
_ ret;
REP(i,0,1) {
ret.L[i]=min(L[i],rhs.L[i]);
ret.R[i]=max(R[i],rhs.R[i]);
}
return ret;
}
} tr[N<<2],tmp[N<<2]; void build(int o, int l, int r) {
if (l==r) return tmp[o].upd(s[l]=='1',l,r);
build(ls),build(rs);
tmp[o]=tmp[lc]+tmp[rc];
}
void upd(int o) {
if (tim[o]!=clk) tr[o]=tmp[o],tim[o]=clk;
}
void update(int o, int l, int r, int ql, int qr, int v) {
upd(o);
if (ql<=l&&r<=qr) return tr[o].upd(v,l,r);
else {
upd(lc),upd(rc);
if (mid>=ql) update(ls,ql,qr,v);
if (mid<qr) update(rs,ql,qr,v);
tr[o]=tr[lc]+tr[rc];
}
}
int chk() {
REP(i,0,1) if (tr[1].R[i]-tr[1].L[i]+1<=k) return 1;
return 0;
} int work() {
scanf("%d%d%s", &n, &k, s+1);
build(1,1,n);
++clk,upd(1);
if (chk()) return 1;
int cnt = 0;
REP(i,1,n-k+1) {
int f = 0;
++clk, update(1,1,n,i,i+k-1,1), f += chk();
++clk, update(1,1,n,i,i+k-1,0), f += chk();
if (f==2) ++cnt;
}
return cnt==n-k+1?0:-1;
} int main() {
int t = work();
if (t==1) puts("tokitsukaze");
else if (t==-1) puts("once again");
else puts("quailty");
}
Tokitsukaze and Duel CodeForces - 1191E (博弈论)的更多相关文章
- E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)
"Duel!" Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty ha ...
- [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)
[Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...
- Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取
https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...
- Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 1190C. Tokitsukaze and Duel
传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...
- Codeforces 1190C Tokitsukaze and Duel game
题意:有一个长为n的01串,两个人轮流操作,每个人可以把某个长度为m的区间变成相同颜色,谁在操作后整个串颜色相同就赢了.问最后是谁赢?(有可能平局) 思路:容易发现,如果第一个人不能一击必胜,那么他就 ...
- C. Tokitsukaze and Duel 前缀维护
枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...
- Financiers Game CodeForces - 737D (博弈论)
直接暴力区间DP的话是$O(n^3)$, 关键注意到每步走的距离差不超过1, 所以差最大是$O(\sqrt{n})$的, 所以实际上有用的状态是$O(n^2)$的, 可以通过.
- Future Failure CodeForces - 838C (博弈论,子集卷积)
大意: 两人轮流操作一个长$n$, 只含前$k$种小写字母的串, 每次操作删除一个字符或者将整个串重排, 每次操作后得到的串不能和之前出现过的串相同, 求多少种串能使先手必胜. 找下规律发现$n$为奇 ...
随机推荐
- 小福bbs——项目需求分析
# 一.简单了解 这个作业属于哪个课程 班级链接 这个作业要求在哪里 作业要求的链接 团队名称 小福bbs 这个作业的目标 第一个版本,根据项目预期情况形成 作业的正文 小福bbs--项目需求分析 其 ...
- Spring Boot项目跳转不到jsp页面是怎么回事
SpringBoot访问不了JSP但却能进入后台 一直报错: 解决方法: 改成下面的
- O(n) O(log n) blist: an asymptotically faster list-like type for Python
https://pypi.org/project/blist/ blist: an asymptotically faster list-like type for Python — blist 1. ...
- 记一次环境变量导致的elasticsearch启动错误:max file descriptors [65535] for elasticsearch process is too low, incre
问题描述,elasticsearch启动时报max file descriptors错误: [hadoop@node-33 elasticsearch-5.4.0]$ bin/elasticsearc ...
- git notes的使用
1. 获取notes git fetch origin refs/notes/*:refs/notes/* 2. 设置notes 2.1 git config --add core.notesRef ...
- Python中的子进程并发
date: 2019-06-16 22:35:33 author: headsen chen notice:个人原创 实例代码: import os,time time.sleep(1) from ...
- 华为OpenStack开源团队人才招募中
职位要求: 1. 三年以上软件开发经验,编程技能良好. 2. 熟练使用Python.Java.Go或其他语言开发. 3. 有OpenStack经验或者存储经验优先考虑. 4. 良好的学习和沟通能力,责 ...
- SpringCloud学习成长之十二 断路器监控
在我的第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard. 一.Hystrix Dashboard简 ...
- spark实现wordcount
spark-shell --master yarnsc:val lineRDD=sc.textFile("/test/input/test")lineRDD.collect().f ...
- CYLTabBarController的简单使用
#pragma mark- 登录成功跳转至主页 -(void)jumpToMainVC { [UIApplication sharedApplication].statusBarStyle = UIS ...