跳到正文

题解

题解 CF1267B 【Balls of Buma】

gyh20约 2 分钟
原文
文章信息与版本

文章信息

发布
2019年12月18日
收录
2026年6月14日
更新
2026年11月15日
篇幅
约 2 分钟
获赞
2
题目
CF1267B

版本

  1. v1当前

贪心

由题可知,必须要最中间的被消除(数量>=2>=2),之后每一个的数量都>=3>=3即可。

方案数即为中间的个数+1+1。

代码:

C++
#include<cstdio>
#include<cstring>
#include<iostream>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();	
	while(v<'0'||v>'9'){
	v=getchar();
	}	
	while(v>='0'&&v<='9'){		
	t=(t<<3)+(t<<1)+(v^48);		
	v=getchar();	}
	return t;
}
char s[300005];
int l,r,cnt;
int main(){
	scanf("%s",s);
	l=0;
	r=strlen(s)-1;
	while(l<=r){
		if(l==r){
			putchar('0');
			return 0;
		}
		cnt=2;
		if(s[l]!=s[r]){
			putchar('0');
			return 0;
		}
		while(s[l+1]==s[l]&&l<r)++l,++cnt;
		while(s[r-1]==s[r]&&r>l)--r,++cnt;
		++l;
		--r;
		if(r<l){
			printf("%d",cnt);
			return 0;
		}
		if(cnt<3){
			putchar('0');
			return 0;
		}
		
	}
}
原文
存档评论1 条抓取于