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. My latest news

    2018.04.12  0:01 本站点停止更新,启用0x7c00.vip站点. 2018.03.23 复试报道(心态不太平稳).每一行的深入都是需要知识的积累和时间的沉淀,就像学法律.计算机等等.愿 ...

  2. 【学习笔记】Spring AOP注解使用总结

    Spring AOP基本概念 是一种动态编译期增强性AOP的实现 与IOC进行整合,不是全面的切面框架 与动态代理相辅相成 有两种实现:基于jdk动态代理.cglib Spring AOP与Aspec ...

  3. header()跳转

    if ($toNews == 1) { header('Location:/ucenter/pageMailBox/2'); exit; } PHP跳转页面,用 header() 函数 定义和用法 h ...

  4. 第10月第20天 afnetwork like MKNetworkEngine http post

    1. + (AFHTTPRequestOperation *)requestSellerWithCompletion:(requestFinishedCompletionBlock)successBl ...

  5. Gson学习记录

    Gson是Google开发来用来序列化和反序列化json格式数据的java库,他最大的特点就是对复杂类型的支持度高,可以完美解决java泛型问题,这得益于他对泛型类型数据的特殊处理,他的缺点就是速度慢 ...

  6. Dream_Spark-----Spark 定制版:004~Spark Streaming事务处理彻底掌握

    Spark 定制版:004~Spark Streaming事务处理彻底掌握 本讲内容: a. Exactly Once b. 输出不重复 注:本讲内容基于Spark 1.6.1版本(在2016年5月来 ...

  7. Java并发——线程同步Volatile与Synchronized详解

    0. 前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52370068 面试时很可能遇到这样一个问题:使用volatile修饰in ...

  8. networkManger介绍

    http://www.linuxidc.com/Linux/2013-08/88809.htm

  9. linux下brctl配置网桥

    原文:http://zhumeng8337797.blog.163.com/blog/static/1007689142011643834429/ 先装好网卡,连上网线,这是废话,不用说了. 然后开始 ...

  10. scp拷贝文件报错-bash: scp: command not found

    今天用scp远程传输资料,报错如下: -bash: scp: command not found 在网上搜资料解决办法如下: 安装scp的软件包: # yum install openssh-clie ...