codeforces 761C

n个串长度为m

然后n个串

问可以最少移动多少次

然后是密码中有数字 字母 然后其他的 都至少一个

光标最初在左边

可以直接往右移到最后一个

处理出每行到数字 字母 其他的最小移动数目

然后暴力 列举  数字  字母 其他 出现的行

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<set>
#include<string>

using namespace std;
typedef long long LL;

#define MAXN 55
char str[MAXN];
#define inf  1000000
int num[MAXN],low[MAXN],oth[MAXN];
int main()
{
    int n,len;
    while(scanf("%d%d",&n,&len)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%s",str);
            num[i]=low[i]=oth[i]=inf;
            for(int j=0;j<len;j++)
            {
                int tmp=min(j,len-j);
                if(str[j]>='0'&&str[j]<='9')
                    num[i]=min(num[i],tmp);
                else if(str[j]>='a'&&str[j]<='z')
                    low[i]=min(low[i],tmp);
                else
                    oth[i]=min(oth[i],tmp);


            }
        }
        int ans=inf;

        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                for(int k=0;k<n;k++)
                {
                    if(i==j||i==k||j==k)
                        continue;
                    ans=min(ans,num[i]+low[j]+oth[k]);
                }
        printf("%d
",ans);


    }
    return 0;
}
原文地址:https://www.cnblogs.com/cherryMJY/p/6426050.html