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. linux--- python3环境部署篇

    环境部署 我们在pycharm上都是自己设置的python3解释器的环境变量,使得代码能够正常执行!可是怎么能让我们的python代码在LINUX上跑起来呢? linux是内置python,可是内置的 ...

  2. PAT1111 Online Map【最短路】【dfs】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805358663417856 题意: 给定一个图,每天边上有时间和路 ...

  3. [httpd] httpd server 在低负载的情况下对SYN无响应

    如题: 两台client通过load balance访问httpd server.两个client交互访问.load balance处于fullnat模式. server在低负载情况下,常常对某一个c ...

  4. libvirt虚拟库

    转载自:https://www.ibm.com/developerworks/cn/linux/l-libvirt/index.html Libvirt 虚拟化库剖析   讲到向外扩展计算(比如云计算 ...

  5. 更新node的版本,node没有安装到c盘,安装到了D盘

    百度的很久,只有这一个实用,记录一下 https://www.cnblogs.com/xinjie-just/p/7061619.html

  6. springboot2.0集成shiro出现ShiroDialect报错找不到AbstractTextChildModifierAttrPr

    @Bean public ShiroDialect shiroDialect() { return new ShiroDialect(); } 报错出现找不到org/thymeleaf/process ...

  7. object-c中疑问

    *一般是加在方法的返回值类型声明部分的,比如:-(NSString *)executeSomeThing;+(NSString *)executeAnotherThing; -(int)addOne; ...

  8. Hive为什么要启用Metastore?

    转载来自: https://blog.csdn.net/qq_40990732/article/details/80914873 https://blog.csdn.net/tp15868352616 ...

  9. [Python] Print input and output in table

    Print the input and output in a table using prettyTable. from prettytable import PrettyTable import ...

  10. MSP430入门准备

    为什么选择MSP430? 低功耗是最主要原因,那有人说了,低功耗的片子多了去了,还有比这更低功耗的呢,只能说, 一个是精力有限, 二是430低功耗做的不差,能满足大部分项目的需求, 三是网上430的资 ...