给你一个长度为 \(\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的一个子串。 所以我们此时只需要从头到尾去扫一遍统计前后相等与不相等的最长长度即可。
*/

最新文章

  1. 【分布式】Zookeeper的Leader选举
  2. Windows10
  3. winform(ListView及数据库连接)
  4. android 自定义按钮实现 home键 和返回键
  5. Objective-C中的类目(Category),延展(Extension)
  6. Java 快排
  7. 关于Mybatis的一些随笔
  8. How Classes are Found
  9. 内置对象之request对象
  10. Python标准库01正则表达式
  11. Ubuntu 14.04 安装配置备忘录
  12. 来自后端的突袭? --开包即食的教程带你浅尝最新开源的C# Web引擎 Blazor
  13. IDEA如何查看maven的依赖结构
  14. goaccess生成nginx每日访问纪录
  15. python class 1
  16. 小程序传id值
  17. JSON知识点
  18. 行级安全(Row-Level Security)
  19. 编写 T4 文本模板
  20. WebBench压力测试工具

热门文章

  1. ZooKeeper配额指南(十)
  2. 关于Linux下s、t、i、a权限
  3. perl中的默认变量与Z/map介绍
  4. 1438. Shopaholic
  5. 【LOJbeta round1】ZQC的手办
  6. Filecoin:一种去中心化的存储网络(一)
  7. 设计模式之笔记--抽象工厂模式(Abstract Factory)
  8. caffe Python API 之InnerProduct
  9. react项目中遇到的一些问题
  10. android datepicker timepicker简单用法