Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
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 暴力的更多相关文章
- 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
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(简单DP)
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- 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 ...
- 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 Round #394 (Div. 2) E. Dasha and Puzzle 构造
E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...
随机推荐
- Linux iptables常用命令的使用
为什么会有本文 因为最近帮一个朋友布署一个上网梯子,他那边本来用的是v2ray,但是他想用ssr,但是安装配置ssr过程中出了很多问题,比如linux内核版本4.9有点老,不支持bbr加速.无法连接s ...
- 一个很实用的css3兼容工具很多属性可以兼容到IE6
当你看到这样的效果图是不是已经崩溃了 css3没出来之前大部分人基本都是用图片的方式拼出来的 腾讯邮箱就是这么做的 然后你想和设计说换直角吧.我用图片的好烦的感觉!而且我们还要兼容到ie6 她和你说别 ...
- # 20155337 2016-2017-2 《Java程序设计》第六周学习总结
20155337 2016-2017-2 <Java程序设计>第六周学习总结 教材学习内容总结 •串流(Stream): 数据有来源及目的地,衔接两者的是串流对象.如果要将数据从来源取出, ...
- export DataTable To Excel(C)
static DataTable GetTable() { DataTable table = new DataTable(); // New data table. table.Colu ...
- shell 流程结构
if 判断语句 if [ $a == $b ] then echo "等于" else echo "不等于" fi case分支选择 case $xs in ) ...
- MongoDB 之 Array Object 的特殊操作 MongoDB - 6
相比关系型数据库, Array [1,2,3,4,5] 和 Object { 'name':'DragonFire' } 是MongoDB 比较特殊的类型了 特殊在哪里呢?在他们的操作上又有什么需要注 ...
- str和unicode类
在py2中,分为两类,str和unicode 而在py3中,分为两类,byte和str py2中的str等同于py3中的byte 首先明确一点,我们编辑好一段文本,python并不知道我们的文本是以什 ...
- 阿里云OSS 中文名称地址不对
oss中将该中文名称重命名.再输入一次
- perl6 中将 字符串 转成十六进制
say Blob.new('abcde'.encode('utf8')).unpack("H*"); say '0x'~'abcde'.encode('utf8').unpack( ...
- python 获取二进制文件
import requests response = requests.get('https://www.baidu.com/aladdin/img/tools/ip.png')with open(' ...