Educational Codeforces Round 92 (Rated for Div. 2) C. Good String

题目链接:
https://codeforces.com/problemset/problem/1389/C

思路:

自己写的时候也推出来了。
要么两个数字周期出现。并且长度必须为偶数
要么一个数字。

自己写的时候一直想直接构造出来…
没想到直接是暴力枚举。
对于字符串0-9这种范围还不太敏感。。

直接枚举第一个数字和第二个数字
取最少的就好。

注意:

第一个和第二个字母不同时,长度不能为奇数。如果是奇数,要-1。

AC代码

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N];
int t,n,ans;
int cnt;
int num;
int main()
{
	cin>>t;
	while(t--)
	{
	
		cin>>s;
		ans=0;
		ans=0x3f3f3f3f;
		int n=strlen(s);
		for(int i=0;i<=9;i++)
		{
			for(int j=0;j<=9;j++)
			{
				int x=0,y=0;
				num=0;
				for(int k=0;k<n;k++)
				{
					if(x==0&&s[k]-'0'==i)
					{
						num++;
						x=1;
					}
					else if(x==1&&y==0&&s[k]-'0'==j)
					{
						num++;
						y=1;
					}
					if(x==1&&y==1)
					{
						x=0;
						y=0;
					}
				}
				if(i!=j&&num%2!=0) num--;
				ans=min(ans,n-num);
			}
		}
		cout<<ans<<endl;
		 
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值