Codeforces 1221F Game With String 思维题
题意:有两个人玩游戏,游戏规则如下:有一个长度为n的字符串,这个字符串由 . 和 X 构成,Alice可以选择a个连续的 . 把它们变成X, Bob可以选择连续的b个 . 把它们变成X。题目中保证a > b, Alice先手,问双方都不放水的情况下谁会赢?
思路:注意到a > b这个关键条件,这个条件是本题的突破口。因为a > b, 我们可以把由 . 构成的区间分成四类:1:长度小于b的区间,这种区间谁都无法填充,不用考虑。2:长度大于等于b小于a的区间,这种区间只有b可以填充。3:长度大于等于a小于2 * b的区间。这种区间双方都可以填充,但是这种区间无法变成类型2的区间。4:长度大于等于2 * b的区间。这种区间可以一步变出类型2的区间。首先我们发现,如果存在类型2的区间,Alice一定赢不了,因为Bob才能填充这个区间。并且,如果类型4的区间大于1个,Alice也必输,因为Bob只需选择类型4区间中的一个,变出一个类型2的区间,Bob就必胜了。那么还剩下2种情况:1:没有类型4的区间。这种情况胜负就和类型3的区间数目相关了。2:只有一个类型4的区间,这时Alice还有可能补救一下。我们只需枚举Alice怎么填充,然后判断这样填充是否能必胜即可。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
char s[maxn];
int cnt[5], a, b;
int get(int len) {
if(len < b) return 1;
else if(len >= b && len < a) return 2;
else if(len >= a && len < 2 * b) return 3;
else if(len >= 2 * b) return 4;
return 0;
}
int main() {
int T, re;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &a, &b);
scanf("%s", s + 1);
memset(cnt, 0, sizeof(cnt));
int n = strlen(s + 1);
int len = 0;
for (int i = 1; i <= n; i++) {
if(s[i] == '.') len++;
else {
cnt[get(len)]++;
if(get(len) == 4) {
re = len;
}
len = 0;
}
}
cnt[get(len)]++;
if(get(len) == 4) {
re = len;
}
if(cnt[2] > 0) {
printf("No\n");
continue;
}
if(cnt[4] > 1) {
printf("No\n");
continue;
}
if(cnt[4] == 1) {
bool flag = 0;
for (int i = 0; i <= re - a; i++) {
int len1 = i, len2 = re - (i + a), tmp = 0;
if(get(len1) == 2 || get(len1) == 4 || get(len2) == 2 || get(len2) == 4) continue;
if(get(len1) == 3) tmp++;
if(get(len2) == 3) tmp++;
if((cnt[3] + tmp) % 2 == 0) {
printf("Yes\n");
flag = 1;
break;
}
}
if(flag == 0) {
printf("No\n");
}
} else {
if(cnt[3] % 2 == 1) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
}
Codeforces 1221F Game With String 思维题的更多相关文章
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- CodeForces - 427A (警察和罪犯 思维题)
Police Recruits Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- codeforces 848B Rooter's Song 思维题
http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...
- Codeforces 1188B - Count Pairs(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...
- Codeforces 1365G - Secure Password(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 首先考虑一个询问 \(20\) 次的方案,考虑每一位,一遍询问求出下标的这一位上为 \(0\) 的位置上值的 bitwise or,再一遍 ...
- Codeforces 1129E - Legendary Tree(思维题)
Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\}, ...
- Codeforces 156 A——Message——————【思维题】
A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...
- Codeforces ~ 1009B ~ Minimum Ternary String (思维)
题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...
随机推荐
- 730KII 打印机 Win7 2017年11月更新系统补丁后无法打印
卸载11月份编号为KB4048960的系统更新
- $FFT/NTT/FWT$题单&简要题解
打算写一个多项式总结. 虽然自己菜得太真实了. 好像四级标题太小了,下次写博客的时候再考虑一下. 模板 \(FFT\)模板 #include <iostream> #include < ...
- 标签button:点击button按钮时,出现了页面自动刷新的情况
原html: <button class="btn btn-primary" id="btnSubmit" name="btnSubmit&qu ...
- 北风设计模式课程---开放封闭原则(Open Closed Principle)
北风设计模式课程---开放封闭原则(Open Closed Principle) 一.总结 一句话总结: 抽象是开放封闭原则的关键. 1."所有的成员变量都应该设置为私有(Private)& ...
- Netty 系列之 Netty 高性能之道 高性能的三个主题 Netty使得开发者能够轻松地接受大量打开的套接字 Java 序列化
Netty系列之Netty高性能之道 https://www.infoq.cn/article/netty-high-performance 李林锋 2014 年 5 月 29 日 话题:性能调优语言 ...
- LinkedHashSet 源码分析
LinkedHashSet 1)底层由 LinkedHashMap 支持的 Set 接口实现,该 Set 中的元素具有可预知的迭代顺序. 创建实例 /** * 构造一个新的空 set,其底层 Link ...
- Firefox,Chrome使用
Firefox 插件 REDIRECTOR Automatically redirect pages based on user-defined rules. 根据用户定义的规则自动重定向页面的插件. ...
- 【openstf】自己的云测平台——mac安装openstf
openstf的github地址:https://github.com/openstf/stf 上图可以清晰看出openstf的使用场景和效果 openstf是一个web应用程序,用于远程调试智能 ...
- sql 查看表的记录数
select a.name as 表名,max(b.rows) as 记录条数 from sysobjects a ,sysindexes b where a.id=b.id and a.xtype= ...
- vue --》组件的封装 及 参数的传递
vue组件的定义 ● 组件(Component)是Vue.js最强大的功能之一 ● 组件可以扩展HTML元素,封装可重用代码 ● 在较高层面上,组件是自定义元素,Vue.js的编译器为他添加特殊功能 ...