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 ...
随机推荐
- TCP重传问题解决思路
处理线上问题经常会碰到网络抖动的情况, 网络抖动有可能就是TCP重传导致,下面简单说下TCP重传的排查思路,不一定能完全解决问题 1. 找运维同事确定是否是网线问题, 如果是网线问题请更换网线 2. ...
- JS——实现短信验证码的倒计时功能(没有验证码,只有倒计时)
1.功能描述 当用户想要获取验证码时,就点击 免费获取验证码 ,然后开始倒计时,倒计时期间按钮文字为剩余时间x秒,且不可按状态,倒计时结束后,按钮更改为点击重新发送. 2.分析 必须用到定时器.按钮点 ...
- bi api 软件
https://www.interactivebrokers.com.hk/cn/index.php?f=5234&ns=T
- 更改CI框架默认访问路径及去掉index.php
下面是去掉index.php的操作 PHP CodeIgniter(CI)去掉 index.php - Langjun - 博客园 设置访问的默认路径是在
- 关于在TabBar 中添加按钮,并通过block 或代理在控制器中实现响应
相信很多朋友会遇到在TabBar中添加按钮,并要求点击按钮能够实现一些功能,但是当我们自定义的时候,怎么才能在控制器中响应?通常我会用代理或者block,block性能更好,建议使用. 自定义TabB ...
- Nginx负载均衡策略
目前nginx负载均衡支持的5种方式的分配 1. 轮询 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除. upstream backserver { server ...
- FZU 1058 粗心的物理学家
这题有毒.要用long double定义,以及cout控制格式输出. #include<cstdio> #include<cstring> #include<cmath& ...
- X-007 FriendlyARM tiny4412 u-boot移植之内存初始化
<<<<<<<<<<<<<<<<<<<<<<<<< ...
- xml数据传输
- 内网服务器启动报错UNEXPECTED INCONSISTENCY解决方法
一开始进入系统显示reboot and select proper boot device or insert boot media in selected boot device and press ...