题目链接:http://codeforces.com/contest/761/problem/C
题意:
有 n 个字符串,每个字符串的长度是m,如果认定一个字符串是一个密码,则必须满足:
1:至少有1个数字。2:至少有一个小写字母。3:至少有一个 #、*或&
现在有n个光标,每个光标指向这 n 个字符串。现在可以移动光标,最后使得所有光标指向的字符能组成一个密码。(字符串是循环的)
题解:
暴力模拟即可,就是一个题意题。
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int size = 5555, inf = 1 << 26;
int n, m;
string s;
int num[size], ltr[size], oth[size];
#define isdig(n) n >= '0' && n <= '9'
#define isalp(c) c >= 'a' && c <= 'z'
#define isoth(c) c == '&' || c == '*' || c == '#'
// version 4 by tyf 17-2-1
int main() {
#ifdef Files
freopen("C2.in", "r", stdin);
#endif
cin >> n >> m;
for ( int i = 0; i < n; i ++ ) {
cin >> s; num[i] = ltr[i] = oth[i] = inf;
for ( int j = 0; j < m; j ++ ) {
int temp = min(j, m-j);
if(isdig(s[j])) num[i] = min(num[i], temp);
else if(isalp(s[j])) ltr[i] = min(ltr[i], temp);
else if(isoth(s[j])) oth[i] = min(oth[i], temp);
}
}
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 || j == k || i == k ) continue;
int temp = num[i]+ltr[j]+oth[k];
ans = min(ans, temp);
}
}
}
printf("%d\n", ans);
return 0;
}