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 ...
随机推荐
- bzoj千题计划230:bzoj3205: [Apio2013]机器人
http://www.lydsy.com/JudgeOnline/problem.php?id=3205 历时一天,老子终于把它A了 哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈 因为不懂spfa ...
- xmlhttprequest upload
html5 带进度上传 function fileSelected() { var file = document.getElementById('fileToUpload').files[0]; i ...
- 玩转Hook——Android权限管理功能探讨(一)
随着Android设备上的隐私安全问题越来越被公众重视,恶意软件对用户隐私,尤其是对电话.短信等私密信息的威胁日益突出,各大主流安全软件均推出了自己的隐私行为监控功能,在root情况下能有效防止恶意软 ...
- SpringBoot框架的权限管理系统
springBoot框架的权限管理系统,支持操作权限和数据权限,后端采用springBoot,MyBatis,Shiro,前端使用adminLTE,Vue.js,bootstrap-table.tre ...
- Eric6启动时“无法定位序数4540于动态链接库LIBEAY32.dll”的错误
参考自:https://blog.csdn.net/HongAndYi/article/details/80721478 在安装PyQt5的编程环境时,安装Eric6-17.12后运行eric6,却出 ...
- 苹果ANCS协议学习【转】
苹果ANCS协议学习 转自:http://www.cnblogs.com/alexcai/p/4321514.html 综述 苹果通知中心(Apple Notification Center Serv ...
- 数据库索引和SQL语句使用经验
1.如果检索数据量超过30%的表中记录数,使用索引将没有显著的效率提高 2.在特定情况下,使用索引也许会比全表扫描慢,但这是同一个数量级上的差距:而通常情况下,使用索引比全表扫描要快几倍乃至几千倍! ...
- 大数据的常用算法(分类、回归分析、聚类、关联规则、神经网络方法、web数据挖掘)
在大数据时代,数据挖掘是最关键的工作.大数据的挖掘是从海量.不完全的.有噪声的.模糊的.随机的大型数据库中发现隐含在其中有价值的.潜在有用的信息和知识的过程,也是一种决策支持过程.其主要基于人工智能, ...
- [原创]Sql2008 使用TVP批量插入数据
TVP(全称 :Table-Valued Parameter) 叫做表值参数(Table-Valued Parameter)是SQL2008的一个新特性.顾名思义,表值参数表示你可以把一个表类型作为参 ...
- 字符串格式化格式 -- Numeric Format Strings