Codeforces 305E Playing with String 博弈
我们可以把每段连续可以选的字符看成一个游戏, 那么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 博弈的更多相关文章
- codeforces 305E Playing with String
刚开始你只有一个字符串每次能选择一个有的字符串s,找到i,满足s[i - 1] = s[i + 1],将其分裂成3 个字符串s[1 ·· i - 1]; s[i]; s[i + 1 ·· |s|] ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Playing with String(codeforces 305E)
题意:刚开始你只有一个字符串每次能选择一个有的字符串 s,找到 i,满足s[i - 1] = s[i + 1],将其分裂成 3 个字符串s[1 · · · i - 1]; s[i]; s[i + 1 ...
- 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 ...
- CodeForces 176C Playing with Superglue 博弈论
Playing with Superglue 题目连接: http://codeforces.com/problemset/problem/176/C Description Two players ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
- codeforces 632C The Smallest String Concatenation
The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...
- 【Codeforces 1120C】Compress String
Codeforces 1120 C 题意:给一个串\(S\),将这个串分成\(t_1..t_m\),如果\(t_i\)在\(t_1..t_{i-1}\)中作为子串出现过,那么这个的代价是\(b\),否 ...
随机推荐
- python操作三大主流数据库(4)python操作mysql④python服务端flask和前端bootstrap框架结合实现新闻展示
python操作mysql④python服务端flask和前端bootstrap框架结合实现新闻展示 参考文档http://flask.pocoo.org/docs/0.11/http://flask ...
- Select查询命令
一开始SELECT查询的命令为 SELECT * FROM employee; SELECT 要查询的列名 FROM 表名字 WHERE 限制条件; 若要查询所有内容,就用*代 ...
- C# pdf转word
引用组件 Spire.Pdf,去官网下载安装,在bin目录里面有需要的dll文件. static void Main(string[] args) { #region Pdf转word PdfDocu ...
- re_test
https://www.cnblogs.com/zhaof/p/6925674.html#4152933 https://www.cnblogs.com/lanyinhao/p/9165747.htm ...
- mongoDB基础使用
环境交代 操作系统: CentOS 6.8 64位 mongodb: 4.06 安装 官方下载地址:https://www.mongodb.org/dl/linux/x86_64-rhel62 阿里云 ...
- Vuejs的一些总结
http://blog.csdn.net/xllily_11/article/details/52312044 原文链接:http://mrzhang123.github.io/2016/07/14/ ...
- android中调用c++文件并转为so
1.新建项目,不选include support c++ 报错:Error:Failed to open zip file.Gradle's dependency cache may be corru ...
- Ionic 2: ReferenceError: webpackJsonp is not defined
I'm new to Ionic. I have started project with super template. But when I try to run the app in brows ...
- 如何在cmd中执行python文件
打开cmd终端 输入python 然后再输入要执行文件的路径 就可以把python文件运行起来 ...
- Android 基础 二 四大组件 Activity
Activity Intent IntentFilter 一理论概述 一. Activity 用来提供一个能让用户操作并与之交互的界面. 1.1 启动 startActivity(Intent int ...