CodeForces - 761C Dasha and Password CodeForces (枚举)
程序员文章站
2022-06-09 17:41:45
...
题目链接:http://codeforces.com/problemset/problem/761/C点击打开链接
#include <bits/stdc++.h>
using namespace std;
vector<string >s;
int main()
{
int n,m;
cin >> n>>m;
for(int i=0;i<n;i++)
{
string mid;
cin >> mid;
s.push_back(mid);
}
int cnt[3][n];
for(int i=0;i<n;i++)
{
cnt[0][i]=cnt[1][i]=cnt[2][i]=m;
for(int j=0;j<m;j++)
{
int jmid=min(j,m-j);
if(isdigit(s[i][j]))
cnt[0][i]=min(cnt[0][i],jmid);
else if('a'<=s[i][j]&&s[i][j]<='z')
cnt[1][i]=min(cnt[1][i],jmid);
else
cnt[2][i]=min(cnt[2][i],jmid);
}
}
int ans=3*m;
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||k==i)
continue;
ans=min(ans,cnt[0][i]+cnt[1][j]+cnt[2][k]);
ans=min(ans,cnt[0][i]+cnt[2][j]+cnt[1][k]);
ans=min(ans,cnt[1][i]+cnt[0][j]+cnt[2][k]);
ans=min(ans,cnt[1][i]+cnt[2][j]+cnt[0][k]);
ans=min(ans,cnt[2][i]+cnt[0][j]+cnt[1][k]);
ans=min(ans,cnt[2][i]+cnt[1][j]+cnt[0][k]);
}
}
}
cout << ans << endl;
}
上一篇: 动态库和静态库
推荐阅读
-
B. Power Sequence(数学+枚举)Codeforces Round #666 (Div. 2)
-
CodeForces - 908C (暴力枚举)
-
Codeforces 1321 C. Remove Adjacent(贪心枚举)
-
Codeforces Round #661 C. Boats Competition(思维+暴力枚举)
-
CodeForces - 761C Dasha and Password CodeForces (枚举)
-
Codeforces 1020C. Elections 枚举
-
codeforces 1395C(暴力枚举)
-
Codeforces Round #489 (Div. 2) B. Nastya Studies Informatics(数学+枚举优化)
-
CodeForces - 1089G Guest Student (枚举)
-
D. Sequence and Swaps(模拟+枚举) Educational Codeforces Round 99 (Rated for Div. 2)