C. Dasha and Password

题目连接:

http://codeforces.com/contest/761/problem/C

Description

After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements:

There is at least one digit in the string,

There is at least one lowercase (small) letter of the Latin alphabet in the string,

There is at least one of three listed symbols in the string: '#', '*', '&'.

Considering that these are programming classes it is not easy to write the password.

For each character of the password we have a fixed string of length m, on each of these n strings there is a pointer on some character. The i-th character displayed on the screen is the pointed character in the i-th string. Initially, all pointers are on characters with indexes 1 in the corresponding strings (all positions are numbered starting from one).

During one operation Dasha can move a pointer in one string one character to the left or to the right. Strings are cyclic, it means that when we move the pointer which is on the character with index 1 to the left, it moves to the character with the index m, and when we move it to the right from the position m it moves to the position 1.

You need to determine the minimum number of operations necessary to make the string displayed on the screen a valid password.

Input

The first line contains two integers n, m (3 ≤ n ≤ 50, 1 ≤ m ≤ 50) — the length of the password and the length of strings which are assigned to password symbols.

Each of the next n lines contains the string which is assigned to the i-th symbol of the password string. Its length is m, it consists of digits, lowercase English letters, and characters '#', '*' or '&'.

You have such input data that you can always get a valid password.

Output

Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.

Sample Input

3 4

12

a3*0

c4

Sample Output

1

Hint

题意

作者想每一行都挑选出一个字符作为密码,然后使得整个密码至少有一个数字,一个小写字母,一个'#'/'&'/'*'字符,问你最少移动多少次光标。

这个字符都是环状的。

题解:

1.预处理dp[i][j]表示第i行拿到字母/数字/符号的最小步数,然后选择三行拿就好了,复杂度n^3。

2.直接暴力枚举就好了。。。n^4

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 105;
string s[maxn];
int id[maxn],n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
cin>>s[i];
int ans = 9999999;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if(i==j)continue;
if(j==k)continue;
if(i==k)continue;
int flag[3];
memset(flag,0,sizeof(flag));
for(int t=0;t<n;t++){
if(t==i||t==j||t==k)continue;
if(s[t][0]<='9'&&s[t][0]>='0')flag[0]=1;
if(s[t][0]<='z'&&s[t][0]>='a')flag[1]=1;
if(s[t][0]=='#'||s[t][0]=='*'||s[t][0]=='&')flag[2]=1;
}
int tmp = 0;
if(flag[0]==0){
int ans1 = 999;
int ans2 = 999;
for(int t=0;t<m;t++){
if(s[i][t]<='9'&&s[i][t]>='0'){
ans1=t;
break;
}
}
for(int t=1;t<m;t++){
if(s[i][(m-t)]<='9'&&s[i][m-t]>='0'){
ans2=t;
break;
}
}
tmp+=min(ans1,ans2);
}
if(flag[1]==0){
int ans1=999;
int ans2=999;
for(int t=0;t<m;t++){
if(s[j][t]<='z'&&s[j][t]>='a'){
ans1=t;
break;
}
}
for(int t=1;t<m;t++){
if(s[j][m-t]<='z'&&s[j][m-t]>='a'){
ans2=t;
break;
}
}
tmp+=min(ans1,ans2);
}
if(flag[2]==0){
int ans1=999;
int ans2=999;
for(int t=0;t<m;t++){
if(s[k][t]=='#'||s[k][t]=='*'||s[k][t]=='&'){
ans1=t;
break;
}
}
for(int t=1;t<m;t++){
if(s[k][m-t]=='#'||s[k][m-t]=='*'||s[k][m-t]=='&'){
ans2=t;
break;
}
}
tmp+=min(ans1,ans2);
}
ans=min(ans,tmp);
}
}
}
cout<<ans<<endl;
}

Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力的更多相关文章

  1. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...

  2. Codeforces Round #394 (Div. 2) C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #394 (Div. 2) C. Dasha and Password(简单DP)

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力

    B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...

  5. Codeforces Round #394 (Div. 2) B. Dasha and friends —— 暴力 or 最小表示法

    题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...

  6. Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)

    http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...

  7. 【枚举】Codeforces Round #394 (Div. 2) C. Dasha and Password

    纪念死去的智商(虽然本来就没有吧……) 三重循环枚举将哪三个fix string作为数字.字母和符号位.记下最小的值就行了. 预处理之后这个做法应该是O(n^3)的,当然完全足够.不预处理是O(n^3 ...

  8. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)

    E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造

    E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...

随机推荐

  1. alloffthelights使用方法

    官网上的demo没有用,因为官网用的jquery是谷歌的CDN,download下来的demo也没有用,因为demo的路径下少了jquery.所以自己写demo的时候要把jquery和alloffth ...

  2. css左右等高问题

    先看看预览效果:http://lgdy.whut.edu.cn/index.php?c=home&a=detail&id=3394 再来谈谈css左右等高的应用场景:在内容管理系统(c ...

  3. Export SQLite data to Excel in iOS programmatically(OC)

    //For the app I have that did this, the SQLite data was fairly large. Therefore, I used a background ...

  4. python中的__getattr__、__getattribute__、__setattr__、__delattr__、__dir__

    __getattr__:     属性查找失败后,解释器会调用 __getattr__ 方法. class TmpTest: def __init__(self): self.tmp = 'tmp12 ...

  5. 第12月第14天 sfml cmake

    1. cd Desktop/mycode/ ls mkdir sfml03 cd sfml03 ls vi main.cpp vi config.h vi CMakeLists.txt ls pwd ...

  6. G - DNA sequence HDU - 1560

    题目链接: https://vjudge.net/contest/254151#problem/G AC代码: #include<iostream> #include<cstring ...

  7. python 入门基础23 选课系统 项目

    选课系统 代码地址:github_code # 选课系统 # 角色:学校.学员.课程.讲师 # 要求: # 1. 创建北京.上海 2 所学校 # 2. 创建linux , python , go 3个 ...

  8. Javascript - 操作符

    操作符(Operator) void 如果void后是数字,就返回NAN,否则返回Undefined. alert(void "hello");//跟的字符 print undef ...

  9. ESXi 6.5 总是会话超时

    ESXi 6.5 客户端Web界面会话超时 在VMware ESXi 6.5中,主机客户端Web界面会话每15分钟自动超时一次,然后您必须再次重新登录ESXi主机客户端Web界面. 要避免这种繁琐的情 ...

  10. 6 个 Linux 运维典型问题,大牛的分析解决思路在这里 【转】

    作为一名合格的 Linux 运维工程师,一定要有一套清晰.明确的解决故障思路,当问题出现时,才能迅速定位.解决问题,这里给出一个处理问题的一般思路: 重视报错提示信息:每个错误的出现,都是给出错误提示 ...