D - Labyrinth

对于位置(i,j), j - c = R - L = const(常数), 其中R表示往右走了几步,L表示往左走了几步

所以R越大, L就越大, R越小, L就越小, 所以只需要最小化L和R中的其中一个就可以了

由于每次变化为0或1,所以用双端队列写bfs, 保证最前面的值最小, 简化版的dijkstra

不过看到好多没写双端队列的也过了......

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e3 + ;
char s[N][N];
int mnr[N][N];
int dir[][] = {, , , , -, , , -};
deque<piii> q;
int n, m;
void bfs(int x, int y, int rx, int ry) {
mem(mnr, 0x3f);
mnr[x][y] = ;
q.push_back({{x, y}, });
while(!q.empty()) {
piii p = q.front();
q.pop_front();
for (int i = ; i < ; i++) {
int xx = p.fi.fi + dir[i][];
int yy = p.fi.se + dir[i][];
if(i == ) {
if( <= xx && xx <= n && <= yy && yy <= m && s[xx][yy] == '.' && p.se + < mnr[xx][yy]) {
mnr[xx][yy] = p.se+;
q.push_back({{xx, yy}, p.se+});
}
}
else {
if( <= xx && xx <= n && <= yy && yy <= m && s[xx][yy] == '.' && p.se < mnr[xx][yy]) {
mnr[xx][yy] = p.se;
q.push_front({{xx, yy}, p.se});
}
}
}
}
}
int main() {
int r, c, x, y;
scanf("%d %d", &n, &m);
scanf("%d %d", &r, &c);
scanf("%d %d", &x, &y);
for (int i = ; i <= n; i++) scanf("%s", s[i]+);
int ans = ;
bfs(r, c, x, y);
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
int cst = j - c;
int l = mnr[i][j] - cst;
if(mnr[i][j] <= y && l <= x) ans++;
}
}
printf("%d\n", ans);
return ;
}

Codeforces 1064 D - Labyrinth的更多相关文章

  1. CF 1064 D. Labyrinth

    D. Labyrinth http://codeforces.com/contest/1064/problem/D 题意: n*m的矩阵,只能往左走l次,往右走r次,上下走无限制,问能走到多少个点. ...

  2. [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]

    题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...

  3. CodeForces 616C The Labyrinth

    先预处理出所有连通块,对于每一个*,看他四周的连通块即可 #include<cstdio> #include<cstring> #include<queue> #i ...

  4. codeforces 1064套题

    a题:题意就是问,3个数字差多少可以构成三角形 思路:两边之和大于第三遍 #include<iostream> #include<algorithm> using namesp ...

  5. Codeforces 1064D/1063B Labyrinth

    原题链接/原题链接(代理站) 题目翻译 给你一个\(n*m\)的迷宫和起始点,有障碍的地方不能走,同时最多向左走\(x\)次,向右走\(y\)次,向上向下没有限制,问你有多少个格子是可以到达的. 输入 ...

  6. [ CodeForces 1063 B ] Labyrinth

    \(\\\) \(Description\) 给出一个四联通的\(N\times M\) 网格图和起点.图中有一些位置是障碍物. 现在上下移动步数不限,向左至多走 \(a\) 步,向右至多走 \(b\ ...

  7. [ CodeForces 1064 B ] Equations of Mathematical Magic

    \(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...

  8. 【Codeforces 1063B】Labyrinth

    [链接] 我是链接,点我呀:) [题意] 你可以往左最多x次,往右最多y次 问你从x,y出发最多能到达多少个格子 只能往上下左右四个方向走到没有障碍的格子 [题解] 假设我们从(r,c)出发想要到固定 ...

  9. Codeforces Round #516 (Div. 2) (A~E)

    目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...

随机推荐

  1. day19 十九、ATM+购物车

    项目:ATM+购物车 作业需求:模拟实现一个ATM + 购物商城程序1.额度 15000或自定义 2.实现购物商城,买东西加入 购物车,调用信用卡接口结账 3.可以提现,手续费5% 4.每月22号出账 ...

  2. JavaScript 世界万物诞生记

    一. 无中生有 起初,什么都没有.造物主说:没有东西本身也是一种东西啊,于是就有了null: 现在我们要造点儿东西出来.但是没有原料怎么办?有一个声音说:不是有null嘛?另一个声音说:可是null代 ...

  3. 对text字段聚合,没有设置fielddate所以出错

    http://192.168.60.26:9200/linewell_assets_mgt_es_yh_test/lw_devices/ _mapping { "properties&quo ...

  4. 格式化输出&初始编码&运算符

    一:格式化输出 %     %d   %s %为占位符   S替换的内容的类型为字符型 d替换的内容为整型 若在格式化输出的时候需要正常用到% 则表示时用两个%%表示 如: name = input( ...

  5. Tomcat的日志分割三种方法

    一.Tomcat的日志分割三种方法 一.方法一:用cronolog分割tomcat的catalina.out文件 Linux 日志切割工具cronolog详解:https://blog.csdn.ne ...

  6. 如何消除img默认的间距

    方案一:div{font-size:0};方案二:img{ display:block};方案三:img{vertical-align:top;}方案四:div{ margin-bottom:-3px ...

  7. Unity中实现人物平滑转身

    using UnityEngine; public class PlayerController : MonoBehaviour { ; ; ; void Update() { hor = Input ...

  8. python将对象名的字符串类型,转化为相应对象的操作方法

    在实际使用Python的过程中,遇到了一个问题,就是定义一个数组,数组内容为对应类名字的字符串. 此时在调用对应的类,生成实例时,需要将字符串转化为相应的类,之后再进行实例化. # coding : ...

  9. phpcms网页替换验证码功能 及 搜索功能

    在使用phpcms替换网页的时候,除了正常的替换栏目.内容页等,其他的什么验证码啦,提交表单了,搜索功能了,这些在替换的时候可能会对一些默认文件有一些小小 的改变 下面就是自己在失败中成功的过程,最后 ...

  10. proto 3 语法

    一.简介 proto3是新版本的protobuf语法.它简化了部分语法,并扩大了支持的语言,Ruby.C#.目前谷歌推荐只在是用新支持的语言或使用新的gRPC框架的时候使用.proto2和proto3 ...