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" ...
随机推荐
- flex兼容问题
display:flex作为C3的新属性,还是有的浏览器不支持的,那下面我们就来说一下他的兼容写法 .box{ display: -webkit-box; /* 老版本语法: Safari, iOS, ...
- win7 注册删除postgresql服务
注册服务 删除服务 备注:都以管理员身份运行dos
- Linux内核调试方法总结之bugreport
bugreport [用途]Android性能分析工具,bugreport记录了Android启动过程日志,启动后的系统状态,包括进程列表.内存信息.VM信息等 [使用方法] Adb bugrepor ...
- 织梦自定义表单导出为excel功能
1.首先在后台修改/dede/templets/diy_main.htm <a href="../plus/diy.php?action=daochu&diyid={dede: ...
- SQL Server创建链接服务器
1.通过sql语句创建链接服务器,数据是sql server的 EXEC sp_addlinkedserver @server='test', --链接服务器别名,自定义 @srvproduct='' ...
- C# out 和 ref 区别
C#里面的 out 和ref参数时常会用到 记录一下: public void Start() { //outSum没必要赋值,赋值了也完全没用. //如果AddByOut函数内部直接使用out对应的 ...
- Jenkins持续集成_03_添加测试报告
前言 Jenkins持续集成自动化测试项目后,可以在控制台输出中查看测试结果,但是这样排查起来往往不够直观.为了更直观的查看测试结果,可以在Jenkins上展示测试报告.测试报告中测试结果情况展示的更 ...
- unity editor 折叠树
https://blog.csdn.net/e295166319/article/details/52370575 需要两个类:树节点类和界面实现类 1:树节点类(TreeNode) using Un ...
- PYTHON2.7之前需要独立安装pip
如果python2版本是>=2.7.9, python3版本是>=3.4, pip已将一起随python安装成功了. 对于Python 2.6,你需要更旧setuptools.适用于Pyt ...
- Cassandra commands
Common commands: describe keyspaces // 列出所有db use your_db; // 进去db describe tables; // 列出所有table ...