AtCoder Beginner Contest 083 - D - Wide Flip(思维)

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, rl+1K must be satisfied). For each integer i such that lir, do the following: if Si is 0, replace it with 1; if Si is 1, replace it with 0.

Constraints

  • 1|S|105
  • Si(1iN) is either 0 or 1.

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

Copy
010

Sample Output 1

Copy
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 3S is now 101.
  • Perform the operation on the segment S[1,2] with length 2S is now 011.
  • Perform the operation on the segment S[2,3] with length 2S 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 long
const 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);
}
 






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值