Codeforces 761C Dasha and Password 【模拟】

题目链接:http://codeforces.com/contest/761/problem/C

 

题意:

有 n 个字符串,每个字符串的长度是m,如果认定一个字符串是一个密码,则必须满足:

1:至少有1个数字。2:至少有一个小写字母。3:至少有一个 #、*或&

现在有n个光标,每个光标指向这 n 个字符串。现在可以移动光标,最后使得所有光标指向的字符能组成一个密码。(字符串是循环的)

题解:

暴力模拟即可,就是一个题意题。

 

#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

const int size = 5555, inf = 1 << 26;
int n, m;
string s;
int num[size], ltr[size], oth[size];

#define isdig(n) n >= '0' && n <= '9'
#define isalp(c) c >= 'a' && c <= 'z'
#define isoth(c) c == '&' || c == '*' || c == '#'

// version 4 by tyf 17-2-1
int main() {
#ifdef Files
	freopen("C2.in", "r", stdin);
#endif

	cin >> n >> m;
	for ( int i = 0; i < n; i ++ ) {
		cin >> s; num[i] = ltr[i] = oth[i] = inf;
		for ( int j = 0; j < m; j ++ ) {
			int temp = min(j, m-j);
			if(isdig(s[j])) num[i] = min(num[i], temp);
			else if(isalp(s[j])) ltr[i] = min(ltr[i], temp);
			else if(isoth(s[j])) oth[i] = min(oth[i], temp);
		}
	}

	int ans = inf;
	for ( int i = 0; i < n; i ++ ) {
		for ( int j = 0; j < n; j ++ ) {
			for ( int k = 0 ; k < n; k ++ ) {
				if( i == j || j == k || i == k ) continue;
				int temp = num[i]+ltr[j]+oth[k];
				ans = min(ans, temp);
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值