Codeforces 761C Dasha and Password(枚举+贪心)
题目链接 Dasha and Password
题目保证一定有解。
考虑到最多只有两行的指针需要移动,那么直接预处理出该行移动到字母数字或特殊符号的最小花费。
然后O(N^3)枚举求最小值即可。
时间复杂度O(N*M+N^3)
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i)
#define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define dec(i,a,b) for(int i(a); i >= (b); --i)
#define for_edge(i,x) for(int i = H[x]; i; i = X[i])
#define INF 1 << 30 const int N = + ;
const int M = + ;
const int Q = + ;
const int A = + ; int a[Q][Q], c[Q][], v[Q][]; char s[Q];
int n, m, ans; int main(){ scanf("%d%d", &n, &m);
rep(i, , n){
scanf("%s", s + );
rep(j, , m){
if (s[j] >= '' && s[j] <= '') a[i][j] = ;
else if (s[j] >= 'a' && s[j] <= 'z') a[i][j] = ;
else if (s[j] == '&' || s[j] == '*' || s[j] == '#') a[i][j] = ;
}
} rep(i, , n) rep(j, , ) c[i][j] = INF; rep(i, , n){
rep(j, , m){
v[i][a[i][j]] = ;
c[i][a[i][j]] = min(c[i][a[i][j]], min(abs(j - ), abs(m - j) + ));
}
} ans = INF;
rep(i, , n - ){
rep(j, i + , n - ){
rep(k, j + , n){
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
if (v[i][] && v[j][] && v[k][]) ans = min(ans, c[i][] + c[j][] + c[k][]);
}
}
} printf("%d\n", ans);
return ; }
Codeforces 761C 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 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- 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 #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- 8 REST Framework 实现Web API 1
1 参考博客: http://blog.csdn.net/SVALBARDKSY/article/details/50548073 2 准备工作 1. 环境 Python: Python 3.5 D ...
- System.AccessViolationException”类型的第一次机会异常在 System.Data.dll 中发生 其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
管理员cmd中运行 netsh winsock reset
- C#编程:正则表达式验证身份证校验码-10
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 我给女朋友讲编程CSS系列(3) CSS如何设置字体的类型、大小、颜色,如何使用火狐浏览器的Firebug插件查看网页的字体
一.CSS如何设置字体的类型.大小.颜色 设计网页时,一般设置body的字体,让其他标签继承body的字体,这样设置特别方便,但是标题标签h1到h6和表单标签(input类型)是没有继承body的字体 ...
- Appium的三种等待时间设置方法
#三种appium设置等待时间的方法 #作者:Mr.Dantes #参考了网上的资料,然后进行了梳理 #第一种 sleep(): 设置固定休眠时间. python 的 time 包提供了休眠方法 ...
- scripts
Shell Script:================================================================ 示例1:[root@server0 ~]# ...
- startActivityForResult用法
使用场景:A界面(activity) 可跳转到一个(假设为 B)或多个子Activity,要求B处理完工作之后返回A 界面,或许同时返回一些数据交给A继续处理.如 由登陆界面A跳转到注册界面B,注册成 ...
- LeetCode with Python -> String
344. Reverse String Write a function that takes a string as input and returns the string reversed. E ...
- c#每循环100次提交一次数据,最后一次不足100次提交一次
StringBuilder sb=new StringBuilder(); string strId=dataGridView1.Rows[dataGridView1.CurrentRow.Index ...
- Spring Cloud Eureka简单入门
步骤: 1.创建父工程 2.创建EurekaServer工程 3.创建EurekaClient工程 父工程pom.xml <?xml version="1.0" encodi ...