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$为奇 ...
随机推荐
- uiautomator代码例子--java
在androidtest下创建文件Ui2Test.java package com.example.myapplication; import android.app.Instrumentation; ...
- Leetcode题 112 和 113. Path Sum I and II
112题目如下: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addi ...
- REST架构原则初探
目录 什么是RESTful架构? REST 架构原则 资源(Resource) 表现层(Representation) 状态转换(State Transfer) 无状态通信原则 RESUful API ...
- mybatis bind标签
开门见山的说,平时写模糊查询,一直用${name},例如: select * from table where name like '%${name}%' 后来知道了,这样写可能会引发sql注入,于是 ...
- 调用百度地图API的总结
因为项目要用到百度地图,所以先摸索了一下,各种功能官方都有文档,点击可查看,文章的话我就直接写我用到的功能例子了,要用可以直接复制粘贴~ 一.主要涉及到的几个接口(先申请密钥): 1.技术一:坐标转换 ...
- python线程池(转)
ThreadPool: #! /usr/bin/env python # -*- coding: utf-8 -*- import threadpool import time def sayhell ...
- BIM IFC算量
1.基础工程:挖槽.垫层.基础底板.基础墙.地圈梁.暖气沟.回填土等:2.主体工程:梁.板.柱.墙等:3.屋顶工程:挑檐.女儿墙.保温.防水.压顶等:4.装修工程:外墙抹灰.墙裙.门窗套.内墙抹灰.粉 ...
- Django之Form、跨站请求以及cookie、session
Form表单 常规html页面的form表单验证 常规页面中,如果想实现对表单中用户输入信息的数据验证,需要配合Ajax来实现. 使用前我们先来熟悉下函数参数:request,其中包含的意义: req ...
- PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cou ...
- git clone时加上--depth 1
当项目过大时,git clone时会出现error: RPC failed; HTTP curl The requested URL returned error: Gateway Time-out的 ...