问题 3883 --奇特的串(完善程序)

3883: 奇特的串(完善程序)★★★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 23  解决: 6
[提交][状态][命题人:]

题目描述

小A正在解开一个谜题:他获得了一个n位的字符串s,谜题需要小A在s中删掉一些字符,使得s变成一个奇特的串。
如果一个字符串左移一位等于它右移一位,即s2s3s4…sn-1sns1等于sns1s2…sn-2sn-1则称该串为奇特的串


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
char s[200005];
int cnt[10],ed[200005][10];
int main(){
    int T;
    scanf("%d",&T);
    while (T--){
        scanf("%s",s+1);
        int l=strlen(s+1);
        memset(cnt,0,sizeof(cnt));
        for (int i=1; i<=l; i++)
            cnt[s[i]-'0']++;
        for (int j=0; j<10; j++)
            ed[l+1][j]=l+1;
        for (int i=l; i>=1; i--){
            for (int j=0; j<=9; j++)
                ed[i][j]=ed[i+1][j];
            _______(1)_________
        }
        int res=0;
        for (int i=0; i<=9; i++){
            if (cnt[i]==0) continue;
            res=max(res,_____(2)______);
            for (int j=0; j<=9; j++){
                if (cnt[j]==0) continue;
                if (i!=j){
                    int st=ed[1][i],tot=0,flag=1;
                    while (________(3)_________){
                        tot++;
                        if (flag) {
                            if (ed[st+1][j]>l) break;
                            _________(4)________
                        }
                        else {
                            if (ed[st+1][i]>l) break;
                            _________(5)________
                        }
                        flag=flag^1;
                    }
                    if (tot%2==1) _______(6)________
                    res=max(res,tot);
                }
            }
        }
        printf("%d\n",l-res);
    }
    return 0;
}


输入

第一行输入一个整数t,表示有t组数据

后面t行每行一个字符串s,s由数字0-9组成,2<=|s|<=2e5。


输出

对于每一个样例,输出删掉字符的最小数目。

样例输入
Copy
3
95831
100120013
252525252525
样例输出
Copy
3
5
0

提示

来源

[提交][状态]