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 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
随机推荐
- CSU 1997-Seating Arrangement
Seating Arrangement Mr. Teacher老师班上一共有n个同学,编号为1到n. 在上课的时候Mr. Teacher要求同学们从左至右按1, 2, -, n的顺序坐成一排,这样每个 ...
- loj2056 「TJOI / HEOI2016」序列
当年我还没学cdq的时候在luogu上写过树套树的代码orzzz ref #include <algorithm> #include <iostream> #include & ...
- IOS开发学习笔记010-面向对象的三大特性
面向对象的三大特性 1.封装 2.继承 3.多态 一.封装 将类内部的属性保护起来,在外部不能直接访问,那么如果需要访问怎么办呢? OC提供了set方法来对成员变量进行访问 set方法 1.作用:提供 ...
- load_file()与into outfile函数详解
load_file()函数的使用: 1.使用条件 ①有读取文件的权限 r and (select count(*) from mysql.user)>0 如果返回正常则说明有权限,反之没有 ②文 ...
- php获取当前操作系统类型
如何使用 php 获取当前操作系统类型呢? 严格来说这里分两种情况,一种情况是获取 服务器端 的操作系统类型,一种是获取 客户端 的操作系统类型. 下面将对如何使用php获取这两种情况下的操作系统类型 ...
- gcc学习记录2——多输入文件
首先有两个.c文件:circle.c和circulararea.c. 分别对两个源文件生成目标文件,circle.o和circulararea.o. gcc -c circle.c circularr ...
- 贪吃蛇—C—基于easyx图形库(上):基本控制函数实现 画图程序
自从学了c语言,就一直想做个游戏,今天将之付之行动,第一次写的特别烂,各种bug:就不贴了.今天网上看了好几个贪吃蛇,重新写了一次,做出来的效果还可以. p.s. easyx图形库是为了方便图形学教 ...
- [oldboy-django][2深入django]MVC&MTV
# MVC和MTV MVC = models(数据库) + views(模板html) + controllers(业务逻辑处理) MTV = models(数据库) + template(模板htm ...
- 链表的问题,ListNode问题
算法面试,有关ListNode的问题 class ListNode{ ListNode *next; int val; ListNode(int x): val(x){}}; 在面试的时候,怎么快速想 ...
- LFTP下载远程文件
拓展阅读: https://linux.cn/article-5460-1.html