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

不能操作者负,求先手必胜的一个策略
初始字符串长度不超过5000

将每个字符都能操作的连续的一段作为一个游戏,状态即可表示成这一段的长度

code:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 5005
using namespace std;
char ch,s[maxn];
int n,sg[maxn],l,idx,tmp;
struct DATA{
int l,r,siz;
}list[maxn];
bool ok,bo[maxn],can[maxn],flag;
void read(int &x){
for (ok=,ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
void calc(int k){
for (int i=,t1,t2;i<=k;i++){
t1=(i-)-,t2=k-(i+);
if (t1>&&sg[t1]==-) calc(t1);
if (t2>&&sg[t2]==-) calc(t2);
}
memset(bo,,sizeof(bo));
for (int i=,t,t1,t2;i<=k;i++){
t1=(i-)-,t2=k-(i+),t=;
if (t1>) t^=sg[t1];
if (t2>) t^=sg[t2];
bo[t]=;
}
for (int i=;;i++) if (!bo[i]){sg[k]=i;break;}
}
int main(){
scanf("%s",s+);
n=strlen(s+);
for (int i=;i<n;i++) if (s[i-]==s[i+]) can[i]=;
for (int i=;i<n;i++){
if (can[i]&&!l) l=i;
if (!can[i]&&l) list[++idx]=(DATA){l,i-,i--l+},l=;
}
if (l) list[++idx]=(DATA){l,n-,n--l+};
memset(sg,-,sizeof(sg));
for (int i=;i<=idx;i++){
if (sg[list[i].siz]==-) calc(list[i].siz);
tmp^=sg[list[i].siz];
}
if (tmp){
puts("First");
for (int i=,t;i<=idx;i++){
t=sg[list[i].siz];
for (int j=list[i].l,t1,t2,t3;j<=list[i].r;j++){
t1=(j-)-list[i].l,t2=list[i].r-(j+),t3=;
if (t1>) t3^=sg[t1];
if (t2>) t3^=sg[t2];
if (!(tmp^t^t3)){printf("%d\n",j),flag=;break;}
}
if (flag) break;
}
}
else puts("Second");
return ;
}

codeforces 305E Playing with String的更多相关文章

  1. Codeforces 305E Playing with String 博弈

    我们可以把每段连续可以选的字符看成一个游戏, 那么sg[ i ]表示连续 i 个字符可选的sg值. 然后找找第一个就好啦. #include<bits/stdc++.h> #define ...

  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 176C Playing with Superglue 博弈论

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

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

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

  7. codeforces 632C The Smallest String Concatenation

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

  8. 【Codeforces 1120C】Compress String

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

  9. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

随机推荐

  1. 动态规划——数位dp

    通过先前在<动态规划——背包问题>中关于动态规划的初探,我们其实可以看到,动态规划其实不是像凸包.扩展欧几里得等是具体的算法,而是一种在解决问题中决策的思想.在不同的题目中,我们都需要根据 ...

  2. Facebook 开源安卓版 React Native,开发者可将相同代码用于网页和 iOS 应用开发

    转自:http://mt.sohu.com/20150915/n421177212.shtml Facebook 创建了React Java 库,这样,Facebook 的工程团队就可以用相同的代码给 ...

  3. 基本RC积分电路及原理分析

    电阻R和电容C串联接入输入信号VI,由电容C输出信号V0,当RC (τ)数值与输入方波宽度tW之间满足:τ>>tW (一般至少为10倍以上),这样的电路称为积分电路 在电容C两端(输出端) ...

  4. Android 免费短信获取国家列表和国家代码

    StringBuffer str = new StringBuffer(); for (Map.Entry<Character, ArrayList<String[]>> en ...

  5. Android抓包工具Fiddler抓取数据

    1.手机端设置 2.Fiddler设置监听 Tools/Fiddler options 是否允许监听到https(Fiddler默认只抓取http格式的),首次点击会弹出是否信任fiddler证书和安 ...

  6. 使用jqMobi开发app基础:Badge的使用

    显示效果: 红色的部分就是Badge,能够用来显示数量或者是其它的信息. 使用事实上非常easy,  $.ui.updateBadge("#" + id, res.Msg, &qu ...

  7. C - Surprising Strings

                                   C - Surprising Strings 题意:输入一段字符串,假设在同一距离下有两个字符串同样输出Not surprising ,否 ...

  8. android蓝牙4.0(BLE)开发之ibeacon初步

    一个april beacon里携带的信息如下 ? 1 <code class=" hljs ">0201061AFF4C0002159069BDB88C11416BAC ...

  9. 2015移动安全挑战赛(阿里&看雪主办)第一题分析

    今天在网上看到了阿里移动安全比赛的第一次,并且说难度不大,便拿来看了看. 主体就是找出一个密码输进去,然后看正误. 这个题是纯Java层的一个题,也没用进行什么保护.可以直接反编译. 登陆Button ...

  10. ActiveNotifications

    The NotificationManager can tell you how many notifications your application is currently showing. T ...