E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)
"Duel!"
Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.
There are nn cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly kk consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these nn cards face the same direction after one's move, the one who takes this move will win.
Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.
Input
The first line contains two integers nn and kk (1≤k≤n≤1051≤k≤n≤105).
The second line contains a single string of length nn that only consists of 00 and 11, representing the situation of these nn cards, where the color side of the ii-th card faces up if the ii-th character is 11, or otherwise, it faces down and the ii-th character is 00.
Output
Print "once again" (without quotes) if the total number of their moves can exceed 109109, which is considered a draw.
In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.
Note that the output characters are case-sensitive, and any wrong spelling would be rejected.
Examples
4 2
0101
quailty
6 1
010101
once again
6 5
010101
tokitsukaze
4 1
0011
once again 解题思路:先手和后手要么一出手就赢,要么就会平局,因为两个人都聪明绝顶(暗示脱发),都想赢,如果一出手赢不了,然后两个人就可以重复同一步操作,抵消对方带来的不好影响,因此导致平局
先手必赢条件:1.不用翻转就可以赢
2.翻转长度 k >= n ,那么只要翻转一次就可以赢
3.k < n ,但是只要一次翻转就可以赢
后手赢的条件:那就是先手第一次无论怎么翻转都不能赢,但是到了后手无论何种情况下都能赢
1.k!=1。因为如果先手赢不了,那他就相当于不动序列,留给后手,后手也赢不了
2.2*k>=n,因为后手一出手必须赢,不然先手就可以抵消后手对于序列的影响而导致平局。
3.2*k>=n的时候,那必定会存在一个区间k内的字符一定是相同的,考虑到先手(聪明绝顶,肯定不希望后手赢),那么我们只要让先手无论如何都会输就好了
首尾肯定是不会选的,毕竟先手聪明绝顶。
那么先手肯定会选择中间的k个连续字符,那么我们就枚举中间k个连续字符区间的左右的剩余区间(例如左边的是a区间,右边的是b区间。)我们判的是否a区间为都为0或者1,以及b。 因为先手决定聪明,所以他会尽量不让后手赢,所以就要枚举区间,判定没有一个情况下a和b不是合法的。
并且区间a和区间b也必须是不同的
注意:判断后手赢得条件时,如果暴力判断(n2)会超时,因此用到里“窗体移动”的方法(这个是我在网上看到的,应该是这个叫法),区间k不断向右移动,同时保证左区间a和右区间b也满足条件
要满足条件的话,去加入区间的元素,只要和它的上一位元素(或是下一位元素)比较就可以知道时候满足条件,这样的复杂度就降到了O(n),还有就是注意边界情况的处理。就是左区间或者右区间有且仅有1一个元素的时候,这个时候区间中没有东西可以进行比较,要满足的是区间a和区间b也必须是不同的。
#include<bits/stdc++.h>
using namespace std;
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
const int P = ;
const int inf = 0x3f3f3f3f;
const int maxn = ;
vector<int>one,zero;
int n,k;
int str[maxn];
char s;
int check1(){
if(one.size() == || zero.size() == || k >= n){
return ;
}
int lz = -,rz = -,lo = -,ro = -;
for(int i = ; i <= n ; i++){
if(lz == - && str[i] == ){
lz = i;
}
if(lo == - && str[i] == ){
lo = i;
}
if(lz != - && lo != -) break;
}
for(int i = n ; i >= ; i--){
if(rz == - && str[i] == ){
rz = i;
}
if(ro == - && str[i] == ){
ro = i;
}
if(rz != - && ro != -) break;
}
if(k >= min(ro - lo + ,rz - lz + )) return ;
return ;
}
int check2(){
if(k == ) return ;
if( * k < n) return ;
int len = n - k;
for(int i = ; i < len ; i++){
if(str[i - ] != str[i - ] || str[i + k] != str[i + k + ]) return ;
}
if(str[] == str[n] || str[] == str[k+] || str[n] == str[n - k - ]) return ;
return ;
} int main(){
gbtb;
cin>>n>>k;
for(int i = ; i <= n ; i++){
cin>>s; str[i] = s-'';
if(str[i] == ) one.push_back(i);
else zero.push_back(i);
}
if(check1()){
cout<<"tokitsukaze"<<endl;
}else if(check2()){
cout<<"quailty"<<endl;
}else{
cout<<"once again"<<endl;
}
return ;
}
一个从很久以前就开始做的梦。
E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)的更多相关文章
- Tokitsukaze and Duel CodeForces - 1191E (博弈论)
大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果. 先判断第一步是否能直接赢, 不能的 ...
- 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的区间变成相同颜色,谁在操作后整个串颜色相同就赢了.问最后是谁赢?(有可能平局) 思路:容易发现,如果第一个人不能一击必胜,那么他就 ...
- Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取
https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...
- C. Tokitsukaze and Duel 前缀维护
枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...
- Codeforces 354B 博弈, DP,记忆化搜索
题意:现在有一个字符矩阵,从左上角出发,每个人交替选择一个字符.如果最后字符a数目大于字符b,那么第一个人获胜,否则b获胜,否则平均.现在双方都不放水,问最后结果是什么? 思路:这题需要注意,选择的字 ...
- Ticket Game CodeForces - 1215D 博弈题
题目描述 Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even ...
- Codeforces Round #573 (Div. 1)
Preface 军训终于结束了回来补一补之前的坑发现很多题目题意都忘记了 这场感觉难度适中,F由于智力不够所以弃了,E的话石乐志看了官方英文题解才发现自己已经胡了一大半就差实现了233 水平下降严重. ...
随机推荐
- C# 控制台应用程序从外部传参运行和调试
参考:/*十有三博客*/ 新建一个用于演示的控制台应用程序项目,然后在Program.cs的入口Main方法里编写如下代码 foreach (var arg in args) { Console.Wr ...
- 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包
将项目复制到其地方的时候编译会报错,按照官网方法也不行,从网上查了一个有用的方法如下 打开CSPROJ文件.删除如下代码, <Import Project="..\packages\ ...
- asp.net mvc3用file上传文件大小限制问题
在Windows2008下,如果上传比较大的文件,可能会出现404错误,(请求筛选模块被配置为拒绝超过请求内容长度的请求). 可通过如下方法解决: 打开URTracker根目录下的web.config ...
- SQL Server 语法大全
SQL语句参考,包含Access.MySQL 以及 SQL Server 基础 创建数据库 CREATE DATABASE database-name 删除数据库 drop database dbna ...
- Mybatis中xml文件的时间段动态查询
- office(CVE-2012-0158)漏洞分析报告
2019/9/12 1.漏洞复现 ①发现崩溃 ②找到漏洞所在的函数,下断点,重新跑起来,单步调试,找到栈被改写的地方 ③分析该函数 把MSCOMCTL拖入IDA,查看该函数代码 ④查看调用栈,回溯. ...
- POJ 1068:Parencodings
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22849 Accepted: 13394 De ...
- AD在更新PCB的时候,每次封装都会改变位置?
转载:https://blog.csdn.net/abc87891842/article/details/52538660 3.如果是很多元件的ID不一致, 手动修改太麻烦了, 可以使用AD的 &qu ...
- C语言预处理理论-宏定义2
宏定义21.带参宏和带参函数的区别(1)宏定义是在预处理期间处理的,而函数是在编译期间处理的.这个区别带来的实质差异是:宏定义最终是在调用宏的地方把宏体原地展开,而函数是在调用函数处跳转到函数中去执行 ...
- 关于RxJS 处理多个Http请求 串行与并行方法
mergeMap mergeMap 操作符用于从内部的 Observable 对象中获取值,然后返回给父级流对象. 合并 Observable 对象 123456 import { of } from ...