我们可以把每段连续可以选的字符看成一个游戏, 那么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. apache配置文件语法错误命令:httpd -t

    cmd命令行切换到C:\wamp\bin\apache\apache2.4.9\bin目录 输入httpd -t命令 错误如下: 1.Syntax error on line 92 of C:/Apa ...

  2. 新手-ios

    最近突然让我学习一下ios,之前从未接触过(一脸蒙逼).而且我用的电脑也不是ios操作系统.上网查了下 网友说虚拟机也可以,于是本人从此举用上了ios系统. 需要的安装的工具有: 资源共享给大家: h ...

  3. Java并发编程的4个同步辅助类(CountDownLatch、CyclicBarrier、Semaphore、Phaser)

    我在<JDK1.5引入的concurrent包>中,曾经介绍过CountDownLatch.CyclicBarrier两个类,还给出了CountDownLatch的演示案例.这里再系统总结 ...

  4. TIMESTAMPN(N) WITH LOCAL TIMEZONE数据类型转换

    --TYPE#=231为TIMESTAMP(N) WITH LOCAL TIME ZONE,181为TIMESTAMP(N) WITH TIME ZONEselect u.name || '.' || ...

  5. C语言学习及应用笔记之二:C语言static关键字及其使用

    C语言有很多关键字,大多关键字使用起来是很明确的,但有一些关键字却要相对复杂一些.我们这里要说明的static关键字就是如此,它的功能很强大,相应的使用也就更复杂. 一般来说static关键字的常见用 ...

  6. java基础题刷题中的知识点复习

    将变量转换为字符串方法:(String)待转对象..toString().String.valueOf(待转对象) 对字符串进行操作的方法,使用StringBuffer和StringBuilder定义 ...

  7. SoapUI、Jmeter、Postman三种接口测试工具的比较分析

    前段时间忙于接口测试,也看了几款接口测试工具,简单从几个角度做了个比较,拿出来与诸位分享一下吧.各位如果要转载,请一定注明来源,最好在评论中告知博主一声,感谢.本报告从多个方面对接口测试的三款常用工具 ...

  8. 用ngif 多次判断 Expression has changed after it was checked

    昨天遇到一个问题 ,用ng Expression has changed after it was checked 查了一下说在angular2中,这个错误只会在dev开发模式下出现,在pro发布版本 ...

  9. LeetCode(91):解码方法

    Medium! 题目描述: 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计 ...

  10. 基于BootStrap的Collapse折叠(包含回显展开折叠的对应状态)

    情况描述:为了改善页面上的input框太多,采用∧∨折叠展开,这个小东西来控制,第一次做,记录一下ヾ(◍°∇°◍)ノ゙下边是Code 代码: //html代码 <div id="col ...