给你一个长度为 \(\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【环状字符串/思维】的更多相关文章

  1. CF1025C Plasticine zebra 思维 字符串

    Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  2. CF C. Plasticine zebra (思维)

    题意: 是输入一个只有'w','b'的字符串,可以对他的任意位置切割成两个子串,切割后的右边的子串翻转后再和左边的子串拼起来会得到一个新的字符串,操作次数不限,问能得到的字符串中wb交替出现的最大的长 ...

  3. CF1025C Plasticine zebra

    思路: 不要被骗了,这个操作实际上tm是在循环移位. 实现: #include <bits/stdc++.h> using namespace std; int main() { stri ...

  4. codeforces#505--C Plasticine Zebra

    C. Plasticine zebra time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. 【CF1025C】Plasticine zebra(模拟)

    题意: n<=1e5 思路:可以证明答案即为极长交替出现的串长度之和 需要注意其实这个串是一个环,复制后再做 #include<cstdio> #include<cstring ...

  6. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  7. Codeforces #505(div1+div2) C Plasticine zebra

    题意:给你一段字符串,可以选择任意多的位置,每个位置会反转两边的字符串,问交错的字符串最长是多长? 思路:找规律,仔细分析样例1.假设位置为 1 2 3 4 5 6 7 8 9,反转之后会发现答案是7 ...

  8. CF 1025C Plasticine zebra

    昨晚忘记判只有一个字符的情况fst了呜呜呜 挺有趣的题,昨晚连刚带猜弄出结论 考虑答案的取值,最优答案可能是一个后缀,或者是一个前缀,或者是一个后缀加上前缀 那么翻转之后最优答案的可选值就有了1的前缀 ...

  9. 定长比较环状字符串-------strcat与strncpy的妙用

    题目链接:https://vjudge.net/problem/UVA-1584 题解:用strcpy与strcmp定长比较字符串即可,strcat与strcmp对string不适用,所以只能改写为c ...

随机推荐

  1. Django1.5 自定义用户模型(总结)

    Django系统有自带的超级棒的认证机制,但是默认的用户模型有一点捉急,为了自定义用户模型,看了很多相关的文章,这里做一个总结: 你可以先看一下这篇,对Django的用户模型有一个比较全的了解: 来自 ...

  2. Weblogic 9.2 启动时报错 javax.xml.namespace.QName

    启动Weblogic 时会报错.javax.xml.namespace.QName; local class incompatible: stream classdesc serialVersionU ...

  3. 杭电多校第八场-A-Character Encoding

    题目描述 In computer science, a character is a letter, a digit, a punctuation mark or some other similar ...

  4. Ubuntu12.04 SVN安装过程

    一.安装SVN和配置SVN 1.安装SVN apt-get install subversion 2.创建SVN目录,项目目录和配置文件目录 mkdir /var/svn mkdir /var/svn ...

  5. @JsonField 修改json字段属性名称

    在前后端分离的开发方式中,经常会遇到后端字段名称和前端字段名称定义不一致的问题,比如,后端定义的Bean中的字段名称为createAt,而前端用的字段名称为createTime.这种情况下可以通过在前 ...

  6. 【BZOJ1072】【SCOI2007】排列 [状压DP]

    排列 Time Limit: 10 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 给一个数字串s和正整数d, 统计s有多 ...

  7. 【BZOJ4491】我也不知道题目名字是什么 [线段树]

    我也不知道题目名字是什么 Time Limit: 10 Sec  Memory Limit: 512 MB[Submit][Status][Discuss] Description 给定一个序列A[i ...

  8. Can you answer these queries?(HDU4027+势能线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4027 题目: 题意:n个数,每次区间更新将其数值变成它的根号倍(向下取整),区间查询数值和. 思路:易 ...

  9. MSSQL DBOtherSQL

    --------------------------查询表中的数据------------------------------ --1.请查询出MyStudent表中的所有数据 --下面的语句表示查询 ...

  10. js_时间戳和时间格式之间的转换。

    关于我的理解,简单明了点: 时间戳:把一个日期使用一个数字表示出来,这个数字就是这个日期的秒数. 日期:就是我们常见的时间表现形式. 时间戳对于一般看时间不够直观明了,可是在程序的世界里作用可大了. ...