跳到正文

题解

codeforce CF1389C

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

文章信息

发布
2025年6月12日
收录
2025年12月12日
更新
2026年11月20日
篇幅
约 2 分钟
获赞
1
题目
CF1389C

版本

  1. v1当前
C++
//S1=S2=S3=S4=S5
//AAAAA   	奇 
//S1=S3,S2=S4
//ABAB   	偶 
//CF1389C
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,len;
int num[10];
string s;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++){
		//先清空变量,数组  
		memset(num,0,sizeof(num));
		int mx=0,ans=0;
		cin>>s;
		len=s.size();
		//奇 : aaaaaaaa 
		//统计各个字符出现的数量 
		for(int j=0;j<len;++j){
			num[s[j]-'0']++;
		}
		//求最大的那一个字符 
		for(int j=0;j<10;++j){
			mx=max(mx,num[j]);
		}
		//偶 : abababab 
		for(char i='0';i<='9';++i){
			for(char j='0';j<='9';++j){
				if(i==j)continue;//处理过
				bool flag=0;
				ans=0;
				for(int k=0;k<len;++k){
					if(s[k]==i&&flag==0)flag=1;
					if(s[k]==j&&flag==1){
						++ans;
						flag=0;
					}
				}
				//记录只记录了一个,要乘上2,这样2个数 
				mx=max(mx,ans*2);
			}
		}
		cout<<s.size()-mx<<"\n";
	}
	return 0;
}
原文