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. Confluence wiki——CentOS6.8搭建详解

    参考资料:http://www.cnblogs.com/jackyyou/p/5534231.html http://www.ilanni.com/?p=11989 公司需要搭建WIKI方便员工将一些 ...

  2. 消息队列之RabbitMQ的.Net客户端EasyNetQ

    https://www.cnblogs.com/CoderAyu/p/9072408.html http://www.cnblogs.com/panzi/p/6337568.html http://w ...

  3. 使用storyboard显示UITableView时,如果不修改系统默认生成的tableView:cellForRowAtIndexPath:方法中的代码,则必须为UITableViewCell注册(填写)重用标识符:identifier.必须要代码方法中的标识符一致.

    CHENYILONG Blog 使用storyboard显示UITableView时,如果不修改系统默认生成的tableView:cellForRowAtIndexPath:方法中的代码,则必须为UI ...

  4. MD5小彩虹表

    为方便日常查询,需要一个MD5小彩虹表,当然网上有比较多的这样的查询站点,但感觉最近使用起来十分不便. 因此,编写一个小程序,用来查询一些经常出现的MD5,也即弱口令MD5查询.采用python3编写 ...

  5. Thinkpad X220 升级 Windows 10 后无线网卡消失问题

    11年购买的Thinkpad X220从Win7升级到Win10后,用着还是挺顺手的,网络显示等一切正常,直到今天合上盖子电脑睡眠以后再次打开,wifi消失不见.重启,关机再开机,都没用,只显示有线网 ...

  6. mysql区间范围查询问题

    一,日期区间查询,表里有一个时间字段 最常见的就是某时间段查询,比如xxxx时间---xxxx时间有多少条数据.例如数据库里的字段是 income_period, 该字段类型可以是字符串(varcha ...

  7. 查看IP以及连接数

    AWK: time awk 'BEGIN{while("netstat -an"|getline){if( $5 ~ /[1-255]/){split($5,t1,":& ...

  8. %08lx

    u-boot中代码如下: debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr); 对应设备上的打印消息如下: N ...

  9. express-partials使用方法

    1.安装express-partials 方法一:运行cmd用npm install express-partials 方法二:在package.json里面的dependencies添加" ...

  10. 【Unity_UWP】Unity 工程发布win10 UWP 时的本地文件读取 (上篇)

    Universal Windows Platform(UWP)是微软Windows10专用的通用应用平台,其目的在于在统一操作系统下控制所有智能电子设备. 自从Unity 5.2之后,配合VS 201 ...