AtCoder Beginner Contest 083
来源:互联网 发布:远程oracle数据库拷贝 编辑:程序博客网 时间:2024/06/07 05:49
D - Wide Flip
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
You are given a string S consisting of 0
and 1
. Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0
by repeating the following operation some number of times.
- Choose a contiguous segment [l,r] in S whose length is at least K (that is, r−l+1≥K must be satisfied). For each integer i such that l≤i≤r, do the following: if Si is
0
, replace it with1
; if Si is1
, replace it with0
.
Constraints
- 1≤|S|≤105
- Si(1≤i≤N) is either
0
or1
.
Input
Input is given from Standard Input in the following format:
S
Output
Print the maximum integer K such that we can turn all the characters of S into 0
by repeating the operation some number of times.
Sample Input 1
010
Sample Output 1
2
We can turn all the characters of S into 0
by the following operations:
- Perform the operation on the segment S[1,3] with length 3. S is now
101
. - Perform the operation on the segment S[1,2] with length 2. S is now
011
. - Perform the operation on the segment S[2,3] with length 2. S is now
000
.
找出最大的k,满足题意。哈哈哈哈哈,实在不想翻译,偷懒一波
POINT:
如果k是x,
那么比如11101000,从左开始数,第k+1开始到末尾都可以任意变0,1。 比如变个[1,k]和[1,k+1],那么k+1这个位置就变了。
从右开始数,那么[1,len-k]都可以任意变0,1。所以我们只要遍历x,然后找到他们从左从右都不能任意变的重合位置,判断这些位置上的值是不是相同的,若相同
则这个x可以,不相同就绝对不能成功。
感觉做的有点蠢。
#include <set>#include <map>#include <math.h>#include <vector>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;#define LL long longconst double pi = acos(-1);const double g = -9.8;const int maxn = 1e5+555; int main(){char s[maxn];scanf("%s",s);int ll=strlen(s);int ans=ll/2;int l,r;while(1){l=ll-ans;r=ans+1;int flag=1;int now=s[l-1];for(int i=l;i<r;i++){if(s[i]!=now){flag=0;break;}}if(!flag){break;}ans++;}printf("%d\n",ans);}
- AtCoder Beginner Contest 083
- AtCoder Beginner Contest 055
- AtCoder Beginner Contest 052
- AtCoder Beginner Contest 057
- AtCoder Beginner Contest 063
- AtCoder Beginner Contest 069
- AtCoder Beginner Contest 069
- AtCoder Beginner Contest 070
- AtCoder Beginner Contest 072
- AtCoder Beginner Contest 072
- AtCoder Beginner Contest 072
- AtCoder Beginner Contest 073
- AtCoder Beginner Contest 072
- AtCoder Beginner Contest 075
- AtCoder Beginner Contest 081
- AtCoder Beginner Contest 081
- AtCoder Beginner Contest 082
- AtCoder Beginner Contest 082
- C/S B/S架构区别
- Oracle之物化视图
- linux 找出两个txt文件中内容不同的部分并输出
- Jenkins+maven+tomcat
- Foundation5(二十)
- AtCoder Beginner Contest 083
- 让owncloud成为微博式记事本
- android 脱壳工具
- 图论算法-网络最大流【EK;Dinic】
- mybatis 中哪些数据库支持 useGeneratedKeys="true"
- Android ROM包探索
- ubuntu16.04基本装机
- 03-C#变量的使用
- 235. Lowest Common Ancestor of a Binary Search Tree