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批量解析域名a记录
#encoding:utf-8 import requests import json import dns.resolver import sys reload(sys) sys.setdefaul ...
- https 对 json空对象解析的影响
2017年11月24日09:56:01 记录一个问题: PHP返回json给APP(安卓, fastjson) 其中一个值是空对象 json_encode( [ 'aaa' => new st ...
- sysstat-----获取服务器负载历史记录
sysstat工具与负载历史回放 很多系统负载过高的时候我们是无法立即获知或者立即解决的,当检测到或者知道历史的高负载状况时,可能需要回放历史监控数据,这时 sar 命令就派上用场了,sar命令同样来 ...
- 监听 input上传文件, 获取文件名称,
<div class="import-box pr" > <span class="model-address-txt">导入文件:&l ...
- windows 系统纯净版官网下载地址
http://www.imsdn.cn/operating-systems/windows-7/
- Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy (default-cli) on project Resource: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
1.问题描述 在 DOS 下执行 tomcat7-maven-plugin 插件部署,启动 Apache Tomcat 服务报错如下: D:\2018\code\XXX>mvn tomcat7: ...
- Confluence 6 从一个备份中获得文件附件
页面中的文件附件可以从备份中获得而不需要将备份文件导入到 Confluence 中.这个在用户删掉了附件,但是你还是想恢复这个附件的时候就变得非常有用了. 自动备份和手动备份都允许你进行这个操作,但是 ...
- Confluence 6 从外部小工具中注册访问
希望从 Confluence 中删除一个小工具,你可以选择小工具边上的 URL ,然后单击删除(Delete). 如果你希望取消订阅一个应用的小工具,你需要删除整个订阅.你不能仅仅删除你订阅中的某一个 ...
- Confluence 6 编辑一个站点装饰文件
希望编辑一个站点的 decorator 文件: 进入 > 基本配置(General Configuration) > 布局(Layouts )(在Look and Feel 菜单下面) ...
- CF919F
题意: Alice和Bob玩游戏,每人各有8张牌,牌的大小在0~4之间 每次操作,先手可以选择自己一张牌和对方一张牌求和后%5,将新的牌替代自己拿出的那张牌,以此类推,直到有一个人手中的牌全部是0,则 ...