题意:有两个人玩游戏,游戏规则如下:有一个长度为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 思维题的更多相关文章

  1. 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 ...

  2. Codeforces 515C 题解(贪心+数论)(思维题)

    题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...

  3. CodeForces - 427A (警察和罪犯 思维题)

    Police Recruits Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  4. codeforces 848B Rooter's Song 思维题

    http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...

  5. Codeforces 1188B - Count Pairs(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 虽说是一个 D1B,但还是想了我足足 20min,所以还是写篇题解罢( 首先注意到这个式子里涉及两个参数,如果我们选择固定一个并动态维护另 ...

  6. Codeforces 1365G - Secure Password(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 首先考虑一个询问 \(20\) 次的方案,考虑每一位,一遍询问求出下标的这一位上为 \(0\) 的位置上值的 bitwise or,再一遍 ...

  7. Codeforces 1129E - Legendary Tree(思维题)

    Codeforces 题面传送门 & 洛谷题面传送门 考虑以 \(1\) 为根,记 \(siz_i\) 为 \(i\) 子树的大小,那么可以通过询问 \(S=\{2,3,\cdots,n\}, ...

  8. Codeforces 156 A——Message——————【思维题】

    A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  9. Codeforces ~ 1009B ~ Minimum Ternary String (思维)

    题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...

随机推荐

  1. AT2371 Placing Squares

    题解 考虑\(dp\) \[ dp[i]=\sum_{i=0}^{i-1}dp[j]*(i-j)^2 \] 我们可以设\((i-j)\)为\(x\),那么随着\(i\)向右移动一格,每个\(x\)都是 ...

  2. SpringCloud 教程 (七)服务注册(consul)

    一.consul 简介 consul 具有以下性质: 服务发现:consul通过http 方式注册服务,并且服务与服务之间相互感应. 服务健康监测 key/value 存储 多数据中心 consul可 ...

  3. 网页分页page

    public class PageBean { private int page; // 第几页 private int pageSize; // 每页记录数 private int start; / ...

  4. review star 评论-评分 文本分析

    <!DOCTYPE html> Title 立项背景: 0-突然被限制,无法访问原amazon_asin_reviews_us数据库: 1-原数据库asin类别.厂家信息不明: 2-自然语 ...

  5. error: exportArchive: You don’t have permission to save the file “HelloWorld.ipa” in the folder “HelloWorld”.

    成功clean环境和生成archive文件之后,最后一步导出ipa包,遇到了权限问题: you don’t have permission to save the file “HelloWorld.i ...

  6. 初窥AST

    一个简单的AST示例: AST结构: 里面有program.name.loc.type.comments.tokens 先看program: 重点关注program里面的body这个数组: JS引擎中 ...

  7. Jmeter之用户参数和用户定义的变量

    在调试脚本的时候,可以使用前置处理器中的用户参数组件进行数据的提供,在该数据中可以使用固定值也可以使用变量值. 如果是固定不变的一些配置项,不需要多个值的时候,也可以使用用户已定义的变量组件. 一.界 ...

  8. 每天一个Linux命令(37)kill命令

          Linux中的kill命令用来终止指定的进程(terminate a process)的运行. kill可将指定的信息送至程序.预设的信息为SIGTERM(15),可将指定程序终止.   ...

  9. Temporal-Difference Control: SARSA and Q-Learning

    SARSA SARSA algorithm also estimate Action-Value functions rather than State-Value function. The dif ...

  10. Linux系统中tomcat的安装及优化

    Linux系统中Tomcat 8 安装 Tomcat 8 安装 官网:http://tomcat.apache.org/ Tomcat 8 官网下载:http://tomcat.apache.org/ ...