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


    地址:http://codeforces.com/contest/1389/problem/C

    题意:

    含0~9的字符串,删除最少的字符,实现:

    t2t3....tnt1==tnt1t2......tn-1

    解析:

    可以发现,当长度为奇数的时候,t1=t2=t3...tn,这个时候,整个字符串必须全相等。这个时候,只要求出哪个数字出现次数最多,len-它即可。

    为偶数的时候,奇数下标全相等,偶数下标全相等。构造方式必须是ABABABAB...交错进行

    所以直接暴力枚举即可。10*10的种类。

    #include<bits/stdc++.h>
    #include<iostream>
    #include<cstring>
    #include<string.h>
    #include<cmath>
    #include<map>
    using namespace std;
    typedef long long ll;
    const int maxn=1e5+20;
    int a[maxn],sum[maxn],p[maxn];
    int le;
    string s;
    int check(int a,int b)
    {
        int sum=0;
        int ok=0;
        char c1=a+'0',c2=b+'0';
        for(int i=0;i<le;i++)
        {
            if(!ok&&s[i]==c1)
            {
                ok=1;
            }
            else if(ok&&s[i]==c2)
            {
                ok=0;
                sum+=2;
            }
        }
        return sum;
    }
    int main()
    {
    
        int t;
        scanf("%d",&t);
        while(t--)
        {
            map<char,int>m;
            cin>>s;
             le=s.length();
            int ans=0;
            for(int i=0;i<le;i++)
            {
                m[s[i]]++;
                ans=max(ans,m[s[i]]);
            }
            for(int i=0;i<=9;i++)
                for(int j=0;j<=9;j++)
                {
                    int md=check(i,j);//每次检查,可以实现长度为多少的ABABAB.....
                    ans=max(ans,md);
                }
            cout<<le-ans<<endl;
        }    
    }
  • 相关阅读:
    IPSec (一)
    python 面向过程和面向对象
    一键修改 yum 源为 aliyun 阿里源 Shell 脚本
    第11组Alpha冲刺(6/6)
    第11组Alpha冲刺(5/6)
    第11组 Alpha冲刺(4/6)
    第11组Alpha冲刺(3/6)
    第11组 Alpha冲刺 (2/6)
    第11组 Alpha冲刺 (1/6)
    第11组(73)需求分析报告
  • 原文地址:https://www.cnblogs.com/liyexin/p/13412879.html
Copyright © 2020-2023  润新知