题目大意

两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏

删字符的规则如下:

  1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心

  2. 删掉该字符,同时,他选择的那个字符串分成了两个独立的字符串

现在问,先手是否必胜,如果先手必胜,输出第一步应该删掉第几个字符,有多解的话,输出序号最小的那个

字符串的长度不超过5000,只包含小写英文字母

做法分析

可以这样考虑:将所有的长度大于等于 3(其实只需要找长度为 3 的就行)的奇回文串的中心标记出来

我们将连续的中心视为一个片段,那么,显然,游戏是进行在片段上面的,所以,游戏被分解成了多个子游戏的和

对于每一个片段(子游戏),我们考虑它的 sg 函数,显然,sg 函数只和这个片段的长度有关,于是定义状态 sg[len] 表示长度为 len 的片段的 sg 值。怎么得到当前状态的下一子状态呢?

  如果删掉的是片段的两端,子状态分成了一个长度为 0 和长度为 len-2 的子片段

  如果删掉的是片段的中间,子状态分成了一个长度为 i 和长度为 len-3-i 的子片段

这样,暴力出 sg 值,再依次的枚举第一次删掉的字符就可以解决这题了

参考代码

 #include <iostream>
#include <cstring>
#include <cstdio> using namespace std; const int N=; char buff[N];
int sg[N]; int GET_SG(int len) {
if(sg[len]!=-) return sg[len];
bool vs[N];
memset(vs, , sizeof vs);
vs[GET_SG(len-)]=;
for(int i=; i+i<len; i++) vs[GET_SG(i-)^(GET_SG(len--i))]=;
for(int i=; i<N; i++) if(!vs[i]) return sg[len]=i;
} int hehe(int L, int R) {
int sum=;
for(int i=L+; i<R; i++) if(buff[i-]==buff[i+]) {
int id=i;
while(i<R && buff[i+]==buff[i-]) i++;
sum^=sg[i-id];
}
return sum;
} int main() {
memset(sg, -, sizeof sg);
sg[]=, sg[]=;
for(int i=; i<N; i++) if(sg[i]==-) GET_SG(i);
while(scanf("%s", buff)!=EOF) {
bool flag=;
for(int i=, len=(int)strlen(buff); i<len-; i++) {
if(buff[i-]!=buff[i+]) continue;
if(hehe(, i-)^hehe(i+, len-)) continue;
printf("First\n%d\n", i+);
flag=;
break;
}
if(flag) printf("Second\n");
}
return ;
}

E. Playing with String

题目链接 & AC 通道

Codeforces Round #184 (Div. 2) E. Playing with String

Codeforces Round #184 (Div. 2) E. Playing with String(博弈)的更多相关文章

  1. Codeforces Round #297 (Div. 2)B. Pasha and String 前缀和

    Codeforces Round #297 (Div. 2)B. Pasha and String Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx ...

  2. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  3. Codeforces Round #184 (Div. 2)

    A. Strange Addition (目前的做法好像做烦了) 统计数的\(mask\),表示个.十.百位上是否是0,共8种数. 枚举8种数组成的所有情况\(2^8\),记录最大数量. B. Con ...

  4. Codeforces Round #877 (Div. 2) B. - Nikita and string

    题目链接:http://codeforces.com/contest/877/problem/B Nikita and string time limit per test2 seconds memo ...

  5. Codeforces Round #522 (Div. 2) C. Playing Piano

    C. Playing Piano 题目链接:https://codeforces.com/contest/1079/problem/C 题意: 给出数列{an},现在要求你给出一个数列{bn},满足: ...

  6. Codeforces Round #296 (Div. 2) A. Playing with Paper

    A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...

  7. 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  8. Codeforces Round #354 (Div. 2) C. Vasya and String

    题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...

  9. Codeforces Round #354 (Div. 2) C. Vasya and String 二分

    C. Vasya and String 题目连接: http://www.codeforces.com/contest/676/problem/C Description High school st ...

随机推荐

  1. crossplatform---Nodejs in Visual Studio Code 07.学习Oracle

    1.开始 Node.js:https://nodejs.org OracleDB: https://github.com/oracle/node-oracledb/blob/master/INSTAL ...

  2. 每天一个linux命令(5):rm 命令

    昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所 ...

  3. Activiti 查看流程图

    package com.mycom.processDefinition; import java.io.File; import java.io.IOException; import java.io ...

  4. RFID 读写器 Reader Writer Cloner

    RFID读写器的工作原理 RFID的数据采集以读写器为主导,RFID读写器是一种通过无线通信,实现对标签识别和内存数据的读出和写入操作的装置. 读写器又称为阅读器或读头(Reader).查询器(Int ...

  5. vector的 emplace 和 insert 以及使用vector进行iterator遍历 且 erase的时候注意事项

    vector<int> first;//Size()==2 first.push_back(); first.push_back(); //first.insert(2); vector& ...

  6. reader

    http://git.oschina.net/jayqqaa12/abase-reader https://github.com/JustWayward/BookReader https://gith ...

  7. 实用的插件:跨浏览器复制jQuery-zclip

    Query-zclip是一个复制内容到剪贴板的jQuery插件,使用它我们不用考虑不同浏览器和浏览器版本之间的兼容问题.jQuery-zclip插件需要Flash的支持,使用时记得安装Adobe Fl ...

  8. c#复制包含子目录文件夹代码

    c#没有复制目录的代码,需要通过递归实现复制目录: 需要引用System.IO命名空间,实现代码如下: private static bool CopyDirectory(string SourceP ...

  9. Scala 具体的并行集合库【翻译】

    原文地址 本文内容 并行数组(Parallel Array) 并行向量(Parallel Vector) 并行范围(Parallel Range) 并行哈希表(Parallel Hash Tables ...

  10. SqlServer数据库备份与还原

    http://v.youku.com/v_show/id_XMjA4NzcyNzUy.html http://v.youku.com/v_show/id_XMjA4Nzc0NDQw.html