给你一个长度为 \(\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. [Luogu 2596] ZJOI2006 书架

    [Luogu 2596] ZJOI2006 书架 第一次指针写 FHQ_Treap(省选噩梦数据结构)AC 啦! 省选试机写它,紧张过度失败了. 省选 Day 1 考场写它,写挂了. 省选 Day 1 ...

  2. iOS tag的使用

    一.添加标记 (标记不能为0) UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)]; backBtn.backgr ...

  3. 判定对象是否存活的算法----GC_ROOT算法

    要应用GC_ROOT算法,判定某个对象是否会被回收,关键是要确定root.确定root之后,你就可以根据代码绘制可达链,从而就可以进行分析了,分析哪些对象会被泄漏,哪些对象会被回收,如果GC执行的时候 ...

  4. [J]computer network tarjan边双联通分量+树的直径

    https://odzkskevi.qnssl.com/b660f16d70db1969261cd8b11235ec99?v=1537580031 [2012-2013 ACM Central Reg ...

  5. 【BZOJ】2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛

    [算法]树形DP [题解]没有上司的舞会?233 f[x][0]=∑max(f[v][0],f[v][1]) f[x][1]=(∑f[v][0])+1 #include<cstdio> # ...

  6. bzoj 1058 bst

    因为是数列的维护,所以我们可以考虑用splay来维护,每次在x插入的时候就在x+1前面插入就行了,然后用bst来维护两问的答案,但是应该会tle.我们来考虑这个问题的性质,首先因为这个数列没有删除操作 ...

  7. .net WebAPI返回xml、json格式

    WebAPI返回xml.json格式简单示例 using System.Net.Http.Formatting; public class TestController : ApiController ...

  8. SSH 登录失败:Host key verification failed 的处理方法

    原因就是你之前已经登录过这个服务器了然后改系统啥的了.导致目标主机 key 值不正确.直接把本机的key文件删除即可 sudo rm /home/yourname/.ssh/known_hosts

  9. supervisor 简单使用

    supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态.supervisor使用python开发. 服务端进程为supervisord,主要负责启动自身及其监控的子进程,响应客户端 ...

  10. net_dev_init

    Kernel: 4.12.6 网络设备初始化,主要包括初始化softnet_data,注册收发包软中断等: static int __init net_dev_init(void) { int i, ...