【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】
【链接】 我是链接,点我呀:)
【题意】
给你一个字符串s.
让你在其中的某一些位置进行操作。。
把[1..i]和[i+1..n]翻转。
使得里面01交替出现的那种子串的长度最长。
【题解】
可以用a,b,c,d,e,f,g依次连在一起。然后a和g再连在一起。形成一个环。。
然后你在这个环上模拟这个操作的过程。
就会发现。不管怎么样。
形成的序列都是下列字符串的一个子串(当然有的时候是反过来的。但会发现正反的话,不影响01串的长度。
abcdefgabcdefg
(你会发现在这个环上从a以一定的方向走,总能找到一个按顺序的a,b,c,d,e,f,g.他们的相对位置没有变。
所以在这个扩大了一倍的字符串上做一次01串的查找就好啦
abcdefgabcdefg
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std;
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
const int N =1e5;
bool cmp(int a,int b)
{
return a>b;
}
int m,n;
char s[N+10];
int a[N];
int main()
{
int t,f=0;
scanf("%s",s);
int l=strlen(s);
if(l==1){
cout << 1 << endl;
return 0;
}
int ans=1,z=1;
for(int i=1; i<2*l; i++)
{
if(s[i%l]!=s[(i-1)%l]) z++;
else
{
ans=max(z,ans);
z=1;
}
ans=max(z,ans);
}
ans=min(ans,l);
printf("%d\n",ans);
return 0;
}
【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】的更多相关文章
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring
[链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...
- 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor
[链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. ...
- D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)
B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis
题目链接 让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除. 先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
A : A. Doggo Recoloring time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra
问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw 操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...
- Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解
真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...
- E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...
随机推荐
- map-reduce入门
map-reduce入门 近期在改写mahout源代码,感觉自己map-reduce功力不够深厚,因此打算系统学习一下. map-reduce事实上是一种编程范式,从统计词频(wordCount)程序 ...
- ACM-并查集之小希的迷宫——hdu1272
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 过时的PreferenceActivity导致Fragment显示问题
问题描写叙述: 在一个点击preferenceactivity中某项显示一个Fragment的场景中,出现错误: java.lang.RuntimeException: This should be ...
- Linux下安装JRE和Eclipse IDE for C/C++ Developers
Linux32位,下载eclipse-cpp-luna-R-linux-gtk.tar.gz和jre-8u11-linux-i586.rpm 放到家文件夹中. http://www.eclipse. ...
- Java中对象与引用
初学Java 时.在非常长一段时间里,总认为基本概念非常模糊. 后来才知道.在很多Java 书中.把对象和对象的引用混为一谈. 假设分不清对象与对象引用,那实在没法非常好地理解以下的面向对象技术.把自 ...
- SVGImageView
In essence, I'm trying to layer multiple ImageViews (one of which is a floor plan, the other a recta ...
- 0x57 倍增优化DP
真的是下定了巨大的决心来搞这一讲,果不其然耗了一晚上 开车旅行(真的是NOIP的题吗怎么这么恐怖) 首先,先用set把小A和小B从城市i出发,到达的下一个城市预处理出来. f[i][j][k]表示走了 ...
- HTTP请求与请求头
HTTP 的请求报文分为三个部分 请求行.请求头和请求体,格式如图:一个典型的请求消息头域,如下所示: POST/GET http://download.microtool.de:80/somedat ...
- SMTP协议详解
简单邮件传输协议 (Simple Mail Transfer Protocol, SMTP) 是在Internet传输email的事实标准. SMTP是一个相对简单的基于文本的协议.在其之上指定了一条 ...
- CentOS6.5下nginx-1.8.1.tar.gz的单节点搭建(图文详解)
不多说,直接上干货! [hadoop@djt002 local]$ su root Password: [root@djt002 local]# ll total drwxr-xr-x. root r ...