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 ...
随机推荐
- office web apps部署(一)
准备两台服务器,A服务器作为域控制器,B服务器安装owa 1.配置域服务器A 参考 2.B服务器加入A所创建的域 参考 3.B服务器安装owa 参考 注意: 1.B服务器加入域后,使用A服务器的管理员 ...
- ASer Python学习笔记
最近又开始学习python了,希望自己能坚持下去. 我看的书是thinkingpython,是在豆瓣的python学习组看到的. 连续看了3,4天左右,然后尝试着写了个小程序,复制文件的,代码如下: ...
- 彻底领悟javascript中的this
this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test() { this.x = 1; } 随着函数使用场合 ...
- HDU 5651 xiaoxin juju needs help
组合数杨辉三角打表,这样避免了除法求逆元. #include<cstdio> #include<cstring> #include<cmath> #include& ...
- iOS中GCD的使用小结
http://www.jianshu.com/p/ae786a4cf3b1 本篇博客共分以下几个模块来介绍GCD的相关内容: 多线程相关概念 多线程编程技术的优缺点比较? GCD中的三种队列类型 Th ...
- libtask channel机理及调度理解
学习golang的时候libtask库的代码是一定要看的,需要深入理解chan和携程的运行机制,下面就结合libtask的源码说明下运行原理,如果理解的有偏差欢迎指正 下面是libtask中Chann ...
- Mysql mysql lost connection to server during query 问题解决方法
在linux上新安装的mysql数据库远程连接速度很慢,用Navicate可以正常连接但是时间很长:使用toad连接提示Mysql mysql lost connection to server du ...
- 怎样简单的制作一个CHM格式的帮助文档?
http://jingyan.baidu.com/article/d8072ac446eb7bec95cefd0e.html 怎么制作CHM格式电子书 http://jingyan.baidu.com ...
- STM32中的位带(bit-band)操作(转)
源:STM32中的位带(bit-band)操作 支持了位带操作后,可以使用普通的加载/存储指令来对单一的比特进行读写.在 CM3 中,有两个区中实现了位带.其中一个是 SRAM 区的最低 1MB 范围 ...
- leetcode-004 insertion sort list
package leetcode; class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } ...