给定$n *m$的格子

询问从$(r, c)$开始最多向左走$x$步,向右走$y$步

询问有多少个格子可以从$(r, c)$到达

有障碍物,$n, m \leqslant 2 * 10^3$

对于一个点$(x, y)$,可以发现$(r, c)$到$(x, y)$的一条向左走的步数和向右走的步数之和最小的路径可以使得向左走和向右走最优

感性理解是如果比这个大的话,那么必定向左走和向右走的步数同时都要增加

那么带上向左走的步数和向右走的步数来跑$bfs$即可

注意上下之间的权值为$0$

可以选择将上下缩成一个点或者跑$01$bfs

代码用了一个队列 + 栈来实现双端队列,感觉$stl$的太丑了...

复杂度$O(nm)$

#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
#define re register
#define de double
#define le long double
#define ri register int
#define ll long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define tpr template <typename ra>
#define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
#define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)
extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
}
int wr[], rw;
#define pc(iw) putchar(iw)
tpr inline void write(ra o, char c = '\n') {
if(!o) pc('');
if(o < ) o = -o, pc('-');
while(o) wr[++ rw] = o % , o /= ;
while(rw) pc(wr[rw --] + '');
pc(c);
}
tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; }
tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; }
tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, : ; }
tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, : ; }
}
using namespace std;
using namespace remoon; #define sid 2005
#define aid 4005000 int n, m, r, c, x, y;
int vis[sid][sid];
char s[sid][sid]; inline char gch() {
char c = gc();
while(c != '*' && c != '.') c = gc();
return c;
} struct node {
int x, y, l, r;
node() {}
node(int x, int y, int l, int r) : x(x), y(y), l(l), r(r) {}
} q[aid], st[aid]; int nx[] = { , , , - };
int ny[] = { , -, , }; inline void bfs() {
vis[r][c] = ;
int fr = , to = , top = ;
q[++ to] = node(r, c, , );
while(fr <= to || top) {
node p;
if(top) p = st[top --];
else p = q[fr ++];
int px = p.x, py = p.y, pl = p.l, pr = p.r;
rep(i, , ) {
int dx = px + nx[i], dy = py + ny[i], dl = pl, dr = pr;
if(dx < || dx > n || dy < || dy > m) continue;
if(i == ) dr = pr + ;
if(i == ) dl = pl + ;
if(dl > x || dr > y || vis[dx][dy] || s[dx][dy] == '*') continue;
vis[dx][dy] = ;
if(i == || i == ) q[++ to] = node(dx, dy, dl, dr);
else st[++ top] = node(dx, dy, dl, dr);
}
}
int ans = ;
rep(i, , n) rep(j, , m) ans += vis[i][j];
write(ans);
} int main() {
n = read(); m = read();
r = read(); c = read();
x = read(); y = read();
rep(i, , n) rep(j, , m) s[i][j] = gch();
bfs();
return ;
}

CodeForces 1063B. Labyrinth 性质的更多相关文章

  1. 【非原创】codeforces 1063B Labyrinth 【01bfs】

    学习博客:戳这里 附本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 co ...

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

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

  3. Codeforces 1064D/1063B Labyrinth

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

  4. 【Codeforces 1063B】Labyrinth

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

  5. Codeforces 1142A(性质、暴举)

    队友和大佬都什么几种情况啥的……我是把终点都插了,起点随便选一个,暴举答案莽A. ; ll n, k, a, b, aa, minn = INF, maxx = -; set<ll> bb ...

  6. CF 1063B Labyrinth

    传送门 解题思路 看上去很简单,\(bfs\)写了一发被\(fst\)...后来才知道好像一群人都被\(fst\)了,这道题好像那些每个点只经过一次的传统\(bfs\)都能被叉,只需要构造出一个一块一 ...

  7. Codeforces 1064D Labyrinth(双端队列BFS)

    题意: 给一个图,"*"不可以走,给你一个起点,限制向左走L次,向右走R次,上下不限制,问你最多可以走到多少个格子 思路: BFS,每次将上下走的策略加入队首,左右加入队尾,(相当 ...

  8. Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集

    C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...

  9. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

随机推荐

  1. CDN基础详解

    什么是 CDN?     Origin Server: 源站,也就是做 CDN 之前的客户真正的服务器;   User: 访问者,也就是要访问网站的网民;   Edge Server: CDN 的服务 ...

  2. c语言学习笔记.指针.

    指针: 一个变量,其值为另一个变量的地址,即,内存位置的直接地址. 声明: int *ptr; /* 一个整型的指针,指针指向的类型是整型 */ double *ptr; /* 一个 double 型 ...

  3. Ubuntu 下查看已安装的软件

    Ubuntu 下如何查看已安装的软件 1.查看安装的所有软件 dpkg -l 例如: dpkg -l | grep ftp 2.查看软件安装的路径 dpkg -L | grep ftp 也可以用 wh ...

  4. Dubbo使用

    [注:本文参考<Dubbo入门---搭建一个最简单的Demo框架>,感谢原创作者的知识探索与奉献] 一.Dubbo背景和简介 Dubbo开始于电商系统,因此在这里先从电商系统的演变讲起.  ...

  5. win10产品密钥 win10专业版激活码key

    转载地址:http://www.xitongcheng.com/jiaocheng/xtazjc_article_35407.html https://blog.csdn.net/WangJianku ...

  6. Eloqument 学习

    参考地址:https://d.laravel-china.org/docs/5.5/eloquent#mass-assignment

  7. n*m的矩阵,行和列都递增有序,求是否出现target元素(面试题)

    题目描述:给定一个n*m的矩阵,矩阵的每一行都是递增的,每一列也是递增的,给定一个元素target,问该target是否在矩阵中出现. 思路:先从最左下角的元素开始找,三种情况: 1. 如果该元素大于 ...

  8. Python 中for...esle和while...else语法

    Python的for...else和while...else语法,这是Python中最不常用,最为误解的语法特性之一. Python中的for.while循环都有一个可选的else分支(类似if语句和 ...

  9. c++ primer 6 语句

    没什么重要的东西,异常处理在17章再讲吧

  10. zookeeper的简单使用

    前言 最近项目中要使用基于zookeeper的集中配置管理系统,而对于zookeeper仅在当初使用阿里开源分布式服务调用框架dubbo时简单的了解一下.本 文的主要目的,调用zkclient (ma ...