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 ...
随机推荐
- 【BZOJ2329/2209】[HNOI2011]括号修复/[Jsoi2011]括号序列 Splay
[BZOJ2329/2209][HNOI2011]括号修复/[Jsoi2011]括号序列 题解:我们的Splay每个节点维护如下东西:左边有多少多余的右括号,右边有多少多余的左括号,同时为了反转操作, ...
- oracle的分页查询,mabatis的sql配置
<select id="getCardcaseByPage" resultType="Cardcase" > select * from ( sel ...
- 输入一个网站地址到网站展现的过程以及APR协议(鬼知道中间经历了什么)
以前只知道输入一个网站,然后看着返回琳琅满目的内容,其实中间经历的过程和步骤太多了.为了满足好奇心以及学习需要,特查阅了资料将其记录下来以备后续自己复习. 从我在地址栏输入www.zhihu.com ...
- 【react 条件渲染】在render的html中使用 三元运算符 进行条件渲染
return ( {renderedPages.map(page => ( <Button key={page} onClick={() => onPageChange(page)} ...
- 锁、volatile、CAS 比较
一.锁的劣势 (1) 在JDK1.5之前都是使用synchronized关键字保证同步的,这种通过使用一致的锁定协议来协调对共享状态的访问,可以确保无论哪个线程持有守 护变量的锁,都采用独占的方式来访 ...
- python 类 __call__
__call__ 对象后面加括号,触发执行. 即:对象() 或者 类()() class dog(object): def __init__(self,name): self.name = name ...
- 数据块加密模式以及IV的意思
(本文资料主要来自:http://en.wikipedia.org/wiki/Block_cipher_mode_of_operation) 目前流行的加密和数字认证算法,都是采用块加密(block ...
- android studio 使用CMAKE
前言 之前,每次需要边写C++代码的时候,我的内心都是拒绝的. 1. 它没有代码提示!!!这意味着我们必须自己手动敲出所有的代码,对于一个新手来说,要一个字母都不错且大小写也要正确,甚至要记得住所有 ...
- android studio gradle 国内代理
使用阿里云的国内镜像仓库地址,就可以快速的下载需要的文件 修改项目根目录下的文件 build.gradle : buildscript { repositories { maven{ url 'htt ...
- cocos代码研究(12)UI之Widget学习笔记
理论基础 Widget类,所有UI控件的基类. 这类继承自ProtectedNode和LayoutParameterProtocol. 如果你想实现自己的UI控件,你应该继承这个类. 被 VideoP ...