CF1025C Plasticine zebra【环状字符串/思维】
给你一个长度为 \(\left|s\right|\) 的01串 \(s\) ,每次操作你可以任选一个 \(k\) ,使01串的 \([1,k]\) 和 \((k,\left|s\right|]\) 分别翻转(其中一个区间可以为空),求经过任意次操作后能得到的最长的01交替出现的子串的长度。(实际题目中01用w和b代替)
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define mod 10003
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1<<30;
const int maxn = 1000003;
const double eps = 1e-8;
int t,n,m,q;
int sum[maxn];
int p[maxn],l,r,x,y;
char s[maxn];
LL min(LL x,LL y){return x>y?y:x;}
LL max(LL x,LL y){return x>y?x:y;}
int main()
{
while(~scanf("%s",s+1))
{
LL ans=0,cnt=0;
int n=strlen(s+1);
for(int i=1;i<=n;i++)
{
s[i+n]=s[i];
}
for(int i=1;i<=2*n;i++)
{
if(s[i]!=s[i-1])
ans=max(ans,++cnt);
else cnt=1;
}
cout<<min(ans,n)<<endl;
}
return 0;
}
/*
设原串为s1,s2,...sn,我们将原串拉长一倍得到:S=s1,..sn...s2n
很显然的一个事实:无论将原串如何合法处理,得到的新串始终是S的一个子串。
所以我们此时只需要从头到尾去扫一遍统计前后相等与不相等的最长长度即可。
*/
CF1025C Plasticine zebra【环状字符串/思维】的更多相关文章
- CF1025C Plasticine zebra 思维 字符串
Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CF C. Plasticine zebra (思维)
题意: 是输入一个只有'w','b'的字符串,可以对他的任意位置切割成两个子串,切割后的右边的子串翻转后再和左边的子串拼起来会得到一个新的字符串,操作次数不限,问能得到的字符串中wb交替出现的最大的长 ...
- CF1025C Plasticine zebra
思路: 不要被骗了,这个操作实际上tm是在循环移位. 实现: #include <bits/stdc++.h> using namespace std; int main() { stri ...
- codeforces#505--C Plasticine Zebra
C. Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【CF1025C】Plasticine zebra(模拟)
题意: n<=1e5 思路:可以证明答案即为极长交替出现的串长度之和 需要注意其实这个串是一个环,复制后再做 #include<cstdio> #include<cstring ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces #505(div1+div2) C Plasticine zebra
题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...
- CF 1025C Plasticine zebra
昨晚忘记判只有一个字符的情况fst了呜呜呜 挺有趣的题,昨晚连刚带猜弄出结论 考虑答案的取值,最优答案可能是一个后缀,或者是一个前缀,或者是一个后缀加上前缀 那么翻转之后最优答案的可选值就有了1的前缀 ...
- 定长比较环状字符串-------strcat与strncpy的妙用
题目链接:https://vjudge.net/problem/UVA-1584 题解:用strcpy与strcmp定长比较字符串即可,strcat与strcmp对string不适用,所以只能改写为c ...
随机推荐
- 我的CCF备考指南
CCF计算机软件能力认证(简称CCF CSP认证). 认证涉及知识点: 认证内容主要覆盖大学计算机专业所学习的程序设计.数据结构.算法以及相关的数学基础知识.包括但不限于: (1)程序设计基础 逻辑与 ...
- poj 3376 Finding Palindromes
Finding Palindromes http://poj.org/problem?id=3376 Time Limit: 10000MS Memory Limit: 262144K ...
- LightOJ 1269 - Consecutive Sum Trie树
题意:给出一串序列,求区间连续异或值的最大和最小. 思路:如果不是出在专题里,想不到可以用字典树做.先求前缀异或值,转为二进制,加入Trie树中,如果要求最大,就是尽可能走和当前位数字相反的,这样异或 ...
- NOJ/HUST 1095 校赛 Just Go 线段树模板题
Description There is a river, which contains n stones from left to right. These stones are magic, ea ...
- 【BZOJ3875】【AHOI2014】骑士游戏 [Spfa][DP]
骑士游戏 Time Limit: 30 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 在这个游戏中,JYY一共有两种攻击 ...
- 【BZOJ1038】【ZJOI2008】瞭望塔 [模拟退火]
瞭望塔 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 致力于建设全国示范和谐小村庄的H村村 ...
- 64_k1
KoboDeluxe-0.5.1-22.fc26.x86_64.rpm 13-Feb-2017 22:11 1626454 k3b-17.04.1-1.fc26.x86_64.rpm 25-May-2 ...
- shell 智能获取历史记录功能
vim ~/.inputrc 文件内容: "\e[A": history-search-backward"\e[B": history-search-forwa ...
- BZOJ 4516: [Sdoi2016]生成魔咒——后缀数组、并查集
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4516 题意 一开始串为空,每次往串后面加一个字符,求本质不同的子串的个数,可以离线.即长度为 ...
- webapi-2 接口参数
1. 实例 using System; using System.Collections.Generic; using System.Linq; using System.Net; using Sys ...