Div.2 C. Dasha and Password
2 seconds
256 megabytes
standard input
standard output
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 1in 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.
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.
Print one integer — the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
3 4
1**2
a3*0
c4**
1
5 5
#*&#*
*a1c&
&q2w*
#a3c#
*&#*&
3
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer.

In the second test one of possible algorithms will be:
- to move the pointer of the second symbol once to the right.
- to move the pointer of the third symbol twice to the right...
代码:
#include "cstdio"
#include "algorithm"
#include "cstring"
#include "queue"
#include "cmath"
using namespace std;
;
#define inf 0x3f3f
][];
][];//
int main(){
int n,m;
scanf("%d%d",&n,&m);
;i<;i++){
;j<;j++){
d[i][j]=;
}
}
;i<n;i++){
scanf("%s",s[i]);
}
// memset(d,inf, sizeof(d)); 用inf初始化会溢出导致结果❌卡了好一会
;i<n;i++){
;j<=m/;j++){
'){
d[i][]=min(d[i][],j);
}
if(s[i][j]>='a'&&s[i][j]<='z'){
d[i][]=min(d[i][],j);
}
if(s[i][j]=='#'||s[i][j]=='*'||s[i][j]=='&'){
d[i][]=min(d[i][],j);
}
){
;k<=m/;k++){
'){
d[i][]=min(d[i][],k);
}
else if(s[i][m-k]>='a'&&s[i][m-k]<='z'){
d[i][]=min(d[i][],k);
}
]=min(d[i][],k);}
}
}
}
}
int a,b,c,x=inf;
;i<n;i++){
;j<n;j++){
;k<n;k++){
a=min(d[i][]+d[j][]+d[k][],d[i][]+d[k][]+d[j][]);
b=min(d[k][]+d[i][]+d[j][],d[k][]+d[j][]+d[i][]);
c=min(d[j][]+d[k][]+d[i][],d[j][]+d[i][]+d[k][]);
x=min(x,min(min(a,b),c));
}
}
}
printf("%d\n",x);
;
}
Div.2 C. Dasha and Password的更多相关文章
- 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 ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- 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 ...
- 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 ...
- Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)
http://codeforces.com/contest/761/problem/C 题意:给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字 ...
- 【枚举】Codeforces Round #394 (Div. 2) C. Dasha and Password
纪念死去的智商(虽然本来就没有吧……) 三重循环枚举将哪三个fix string作为数字.字母和符号位.记下最小的值就行了. 预处理之后这个做法应该是O(n^3)的,当然完全足够.不预处理是O(n^3 ...
- 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 ...
- Codeforces 761C Dasha and Password(枚举+贪心)
题目链接 Dasha and Password 题目保证一定有解. 考虑到最多只有两行的指针需要移动,那么直接预处理出该行移动到字母数字或特殊符号的最小花费. 然后O(N^3)枚举求最小值即可. 时间 ...
- 【codeforces 761C】Dasha and Password(动态规划做法)
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- PHP 领域逻辑与数据库映射
http://blog.csdn.net/hguisu/article/details/7569968
- NBUT 1457 Sona
莫队算法+离散化 1.map会TLE,必须离散化做 2.long long会WA,__int64定义 %I64d输出输出能AC 3.注意输入的序列会爆int #include<cstdio> ...
- log4CXX第二篇---配置文件(properties文件)详解
一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...
- FZU 1058 粗心的物理学家
这题有毒.要用long double定义,以及cout控制格式输出. #include<cstdio> #include<cstring> #include<cmath& ...
- IIS日志路径,修改存放位置,清除日志方法
IIS存放日志文件的默认存储路径是c:\windows\system32\logfiles 我们依次打开“我的电脑”,C盘,Windows文件夹,system32文件夹,logfiles文件夹,发现里 ...
- Ural Vol1(dif>=900)
目前已AC: 2 1040.Airline Company(构造) 题目要求与每个顶点相连的所有边编号最大公约数为1,其实只要其中的两条边编号互质,所有边编号的最大公约数一定为1.我们知道相邻的数字 ...
- 【转】国外程序员收集整理的PHP资源大全
ziadoz在 Github发起维护的一个PHP资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等.伯乐在线对该资源列表进行了翻译, ...
- Java中的条件编译(转)
源:Java中的条件编译 一直以来,不知道怎么在Java中实现像C/C++一样的#ifdef...#endif这样的预编译宏,致使Java代码中一直用if判断,刚好刚才看到了解决办法,记录一下. C/ ...
- Keil MDK从未有过的详细使用讲解
转自博客:http://blog.csdn.net/zhzht19861011/article/details/5846510 这博主关于MDK 的使用的文章,写的得TM的好 TM的实用! 真心收藏 ...
- Spark Standalone Mode
It is very easy to install a Spark cluster (Standalone mode). In my example, I used three machines. ...