我们可以把每段连续可以选的字符看成一个游戏, 那么sg[ i ]表示连续 i 个字符可选的sg值。

然后找找第一个就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int sg[N], n;
bool mex[N];
char s[N]; int calc(int l, int r) {
int cnt = , ans = ;
for(int i = l + ; i < r; i++) {
if(s[i - ] == s[i + ]) {
cnt++;
} else {
ans ^= sg[cnt];
cnt = ;
}
}
ans ^= sg[cnt];
return ans;
} int main() {
sg[] = ; sg[] = ; sg[] = ;
for(int i = ; i < N; i++) {
memset(mex, , sizeof(mex));
for(int j = ; j <= i; j++)
mex[sg[max(, j - )] ^ sg[max(, i - j - )]] = true;
for(int j = ; ; j++) {
if(!mex[j]) {
sg[i] = j;
break;
}
}
} scanf("%s", s + );
n = strlen(s + ); int ans = , cnt = ;
for(int i = ; i <= n; i++) {
if(s[i - ] == s[i + ]) cnt++;
else {
ans ^= sg[cnt];
cnt = ;
}
}
if(!ans) {
puts("Second");
} else {
puts("First");
for(int i = ; i <= n; i++) {
if(s[i - ] == s[i + ]) {
if(!(calc(, i - ) ^ calc(i + , n))) {
printf("%d\n", i);
return ;
}
}
}
}
return ;
} /* */

Codeforces 305E Playing with String 博弈的更多相关文章

  1. codeforces 305E Playing with String

    刚开始你只有一个字符串每次能选择一个有的字符串s,找到i,满足s[i - 1] = s[i + 1],将其分裂成3 个字符串s[1 ··  i - 1]; s[i]; s[i + 1 ·· |s|] ...

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

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

  3. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  4. Playing with String(codeforces 305E)

    题意:刚开始你只有一个字符串每次能选择一个有的字符串 s,找到 i,满足s[i - 1] = s[i + 1],将其分裂成 3 个字符串s[1 · · · i - 1]; s[i]; s[i + 1 ...

  5. CodeForces - 1221E Game With String(不平等博弈)

    Alice and Bob play a game. Initially they have a string s1,s2,…,sns1,s2,…,sn, consisting of only cha ...

  6. CodeForces 176C Playing with Superglue 博弈论

    Playing with Superglue 题目连接: http://codeforces.com/problemset/problem/176/C Description Two players ...

  7. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

  8. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

  9. 【Codeforces 1120C】Compress String

    Codeforces 1120 C 题意:给一个串\(S\),将这个串分成\(t_1..t_m\),如果\(t_i\)在\(t_1..t_{i-1}\)中作为子串出现过,那么这个的代价是\(b\),否 ...

随机推荐

  1. ASP.NET 验证码绘制

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. hadoop生态系统主要架构图汇总

    1 hadoop1.0时期架构 2 hadoop2.0时期架构 3 hdfs架构 [Active Namenode]:主 Master(只有一个),管理 HDFS 的名称空间,管理数据块映射信息:配置 ...

  3. [转]GitHub上优秀的Go开源项目

    转载于GitHub上优秀的Go开源项目 正文 近一年来,学习和研究Go语言,断断续续的收集了一些比较优秀的开源项目,这些项目都非常不错,可以供我们学习和研究Go用,从中可以学到很多关于Go的使用.技巧 ...

  4. [javascript]multipart/form-data上传格式表单自定义创建

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  5. Codeforces 833D Red-Black Cobweb [点分治]

    洛谷 Codeforces 思路 看到树上路径的统计,容易想到点分治. 虽然只有一个限制,但这个限制比较麻烦,我们把它拆成两个. 设黑边有\(a\)条,白边有\(b\)条,那么有 \[ 2a\geq ...

  6. 【Windows】添加定时任务不执行

    [问题]windows定时任务不执行.在“所有程序->附件->系统工具->任务计划程序”中添加了定时调用“D:\sys_task\bugmanager\run.bat”脚本的任务计划 ...

  7. libopencv_highgui.so.2.4.9:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用

    make之前加上sudo su重新make即可 http://blog.csdn.net/cfyzcc/article/details/52981467

  8. 【python】打印函数调用栈

    traceback.print_stack()

  9. mysql中的sql

    变量 用户变量: 在用户变量前加@ 系统变量: 在系统变量前加@@ 运算符 算术运算符有: +(加), -(减), * (乘), / (除) 和% (求模) 五中运算 位运算符有: & (位于 ...

  10. laravel 队列发送邮件

    批量处理任务的场景在我们开发中是经常使用的,比如邮件群发,消息通知,短信,秒杀等等,我们需要将这个耗时的操作放在队列中来处理,从而大幅度缩短Web请求和相应的时间.下面讲解下Laravel中队列的使用 ...