Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)
http://codeforces.com/contest/761/problem/C
题意:
给出n个串,每个串的初始光标都位于0(列)处,怎样移动光标能够在凑出密码(每个串的光标位置表示一个密码的字符,密码至少包含3种字符:数字,小写字母,特殊符号)的情况下使得移动的光标步数最小。
思路:
因为每个串只提供一个密码,所以我们先预处理计算出每个字符串3种字符的最少移动步数。
然后接下三重循环枚举,分别表示数字,小写字母,特殊符号由第i,j,k行提供。
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstdio>
using namespace std; const int inf=; int n,m;
char s[][];
int w[][]; int main()
{
//freopen("D:\\input.txt", "r", stdin);
while(~scanf("%d%d",&n,&m))
{
for(int i=;i<n;i++)
scanf("%s",&s[i]);
for(int i=;i<n;i++)
{
w[i][]=w[i][]=w[i][]=inf;
for(int j=;j<m;j++)
{
if(isdigit(s[i][j])) w[i][]=min(w[i][],min(j,m-j));
else if(islower(s[i][j])) w[i][]=min(w[i][],min(j,m-j));
else w[i][]=min(w[i][],min(j,m-j));
}
} int ans=*inf;
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
for(int k=;k<n;k++)
{
if(i==j||j==k||i==k) continue;
ans=min(ans,w[i][]+w[j][]+w[k][]);
}
}
}
printf("%d\n",ans);
}
return ;
}
Codeforces Round #394 (Div. 2) C.Dasha and Password(暴力)的更多相关文章
- 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 —— 枚举
题目链接: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
纪念死去的智商(虽然本来就没有吧……) 三重循环枚举将哪三个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 ...
随机推荐
- Python 中的线程-进程1
原文:https://www.cnblogs.com/i-honey/p/8042047.html 1. 并行和并发 并行:同时做某些事,可以互不干扰的同一时刻做几件事. 并发:也是同时做某些事,但是 ...
- android 软键盘回车键捕获
EditText editText2 = (EditText)findViewById(R.id.txtTest2); editText2.setOnEditorActionListener(new ...
- Comparable 与 Comparator的区别
Comparable & Comparator 都是用来实现集合中元素的比较.排序的,只是 Comparable 是在集合内部定义的方法实现的排序,Comparator 是在集合外部实现的排序 ...
- UUID的定义以及作用
UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, OS ...
- postgresql 表空间创建、删除
表空间:字面上理解就是表存储的物理空间,其实包括数据库的表.索引.序列等. 可以将表空间创建在服务器的不同分区,这样做的好处有: 一.如果初始化集群所在分区已经用光,可以方便的其他分区上创建表空间已达 ...
- 表空间Tablespace
SQL Fundamentals: 表的创建和管理(表的基本操作,闪回技术flashback,表结构修改) Oracle Schema Objects——Tables——TableStorage 数据 ...
- scrapy爬虫系列之六--模拟登录
功能点:如何发送携带cookie访问登录后的页面,如何发送post请求登录 爬取网站:bilibili.github 完整代码:https://files.cnblogs.com/files/book ...
- 比特币BTC全节点搭建
比特币BTC全节点搭建 #环境 ubuntu 16.4 #硬盘500GB #截止2018-12-31磁盘占用超过230GB #客户端安装 #下载页面 #https://bitcoin.org/zh_C ...
- 数据库知识,mysql索引原理
1:innodb底层实现原理:https://blog.csdn.net/u012978884/article/details/52416997 2:MySQL索引背后的数据结构及算法原理 ht ...
- Java打包可执行jar包 包含外部文件
外部文件在程序中设置成相对当前工程路径,执行jar包时,将外部文件放在和jar包平级的目录. public class Main { 3 public static void main(String[ ...