Codeforces 305E Playing with String
来源:互联网 发布:mac vim 命令大全 编辑:程序博客网 时间:2024/05/21 22:24
传送门:http://codeforces.com/problemset/problem/305/E
思路:首先每个字符都可选的子串可以看成一个独立的游戏,那么最终的答案就可以通过所有独立游戏的SG值的异或和得到。
代码:
#include<cstdio>#include<cstring>#include<algorithm>const int n=5010;using namespace std;int sg[n];char s[n];bool bo[n];int getsg(int len){if (sg[len]!=-1) return sg[len];memset(bo,0,sizeof(bo));bo[getsg(len-2)]=1;for (int i=1;i+i<len;i++) bo[getsg(i-1)^getsg(len-i-2)]=1;for (int i=0;i<n;i++) if (!bo[i]) return sg[len]=i;}int getans(int l,int r){int sum=0;for (int i=l+1;i<=r-1;i++) if (s[i+1]==s[i-1]){int len=0;while (s[i+1]==s[i-1]&&i<=r-1) i++,len++;sum^=sg[len];printf("%d\n",len);}return sum;}int main(){memset(sg,-1,sizeof(sg));sg[0]=0,sg[1]=1;for (int i=2;i<n;i++) if (sg[i]==-1) sg[i]=getsg(i);for (int i=0;i<=10;i++) { printf("%d",sg[i]); }while (scanf("%s",s)!=EOF){bool sec=1;for (int i=1,len=strlen(s);i<len-1;i++){if (s[i-1]!=s[i+1]) continue;if (getans(0,i-1)^getans(i+1,len-1)) continue;printf("First\n%d\n",i+1),sec=0;break;}if (sec) puts("Second");}return 0;}
0 0
- Codeforces 305E Playing with String
- codeforces Playing with Dice
- codeforces 251B Playing with Permutations 模拟
- codeforces--12.29--A. Playing with Dice
- Codeforces 527A Playing with Paper
- CodeForces 527A Playing with Paper
- codeforces 527A Playing with Paper
- codeforces 378A Playing with Dice
- 贪心——Playing with numbers ( Gym 101061 E )
- GYM 101061 E.Playing with numbers(单调栈)
- CodeForces 378A Playing with Dice(水题)
- Codeforces Round #222 (Div. 2)---A. Playing with Dice
- Codeforces Round #296 (Div. 2) A. Playing with Paper
- Codeforces Round #296 (Div. 2) -----A. Playing with Paper
- CodeForces 527A Playing with Paper 折纸游戏
- CodeForces 176C Playing with Superglue(游戏)
- codeforces E. Generate a String
- Playing with DataGrid Control
- 重载操作符与转换
- javascript总结
- 数组存储蛇形数据
- AOP 的利器:ASM 3.0 介绍
- 关于js的this
- Codeforces 305E Playing with String
- 一些网址
- Android Fragment 真正的完全解析(上)
- 栈的应用 - 波兰式与逆波兰式的计算
- UIScrollView(滑动切换图片,图片的循环切换(自动))
- 利用Oracle DDL触发器实现DDL监控
- Android图像处理之BitMap(2)
- Android 不同分辨率的logo 尺寸 density 状态栏尺寸
- Android实战技巧:如何在ScrollView中嵌套ListView