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\),否 ...
随机推荐
- JGroups
JGroups Developer(s) Bela Ban Stable release 4.0.10.Final / February 1, 2018 Written in Java Operati ...
- c# 图片插入Excel
引用COM:Microsoft Office 11.0 Object Library 引用类: using System; using System.Windows.Forms; u ...
- JAVA 语言如何进行异常处理,关键字: throws,throw,try,catch,finally分别代表什么意义? 在try块中可以抛 出异常吗?
Java通过面向对象的方法进行异常处理,把各种不同的异常进行分类, 并提供了良好的接口. 在 Java中,每个异常都是一个对象,它是 Throwable 类或其它子类的实例.当一个方法出 ...
- OC对象本质
@interface person:NSObject{ @public int _age; } @end @implementation person @end @interface student: ...
- linux用户
hen we are travelling, we find ourselves in new places and new spaces, physically and internally; it ...
- LeetCode(118):杨辉三角
Easy! 题目描述: 给定一个非负整数 numRows,生成杨辉三角的前 numRows 行. 在杨辉三角中,每个数是它左上方和右上方的数的和. 示例: 输入: 5 输出: [ [1], [1,1] ...
- C#概念总结(三)
1.定义结构体 定义了结构体,必须使用了stuct语句,struct定义了一个带有多个成员的的新数据类型.C# 的结构不同于C的.具有一下等特点: 结构可以有方法.字段.索引.属性.运算方法和事件.结 ...
- java方法重载和重写
1.java的方法重载和重写,表示两种不同的类型.this关键字,出现在类的构造方法中,代表使用该构造方法所创建的对象.,this可以出现在实例方法中核构造方法中.但是不能出现在类方法中.实例方法只能 ...
- antDesign 使用Form并进行表单验证
import React from 'react'; import {Form,Input,Select,Button ...} from 'antd'; class PageName extends ...
- cf1073c 二分+二维前缀和
#include<bits/stdc++.h> using namespace std; #define maxn 200005 char s[maxn]; ][maxn]; map< ...