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$为奇 ...
随机推荐
- Go 与 JSON
Go 中通过标准库encoding/json.encoding.xml.encoding/asn1和其他库对 JSON.XML.ASN.1 和其他类型的标准的编码和解码提供了良好的支持,这里对使用最多 ...
- Sentinel控制台前端开发环境搭建
Sentinel:分布式系统的流量防卫兵. 官网:https://sentinelguard.io Github:https://github.com/alibaba/sentinel Wiki:ht ...
- Struts2 入门笔记
一.介绍 1.Struts网站 https://struts.apache.org/ struts 是通过基于请求响应模式的应用framework 1) 控制器(Controller)--控制整个Fr ...
- linux 之oracle静默安装
一.安装前准备工作1.修改主机名#vi /etc/hosts //并添加内网IP地址对应的hostname,如下127.0.0.1 localhost::1 ...
- Android 定义和使用样式
如图,在stryle.xml中定义样式 然后可以在布局文件中使用样式
- Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考)
ylbtech-Docs-.NET-C#-指南-语言参考-预处理器指令:#line(C# 参考) 1.返回顶部 1. #line(C# 参考) 2015/07/20 借助 #line,可修改编译器的行 ...
- Hibernate 自动更新表出错 建表或添加列,提示标识符无效
如Oracle 数据库下报错: create table db_meta_web.user (id varchar2(255 char) not null, account varchar2(255 ...
- windows下打开binlog
上篇我们介绍了binlog(参见mysql的binlog),配置文件用的是linux下的my.cnf,那么在windows下如何打开binlog呢?道理是相同的,配置文件是不一样的.在windows下 ...
- LeetCode_27. Remove Element
27. Remove Element Easy Given an array nums and a value val, remove all instances of that value in-p ...
- python迭代器、生成器、装饰器之迭代器
迭代是Python最强大的功能之一,是访问集合元素的一种方式. 一般分为可迭代对象,迭代器,可迭代对象不一定是迭代器,但迭代器一定是可迭代对象 1.可以直接作用于for循环的数据类型 第一类:集合数据 ...