给定$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. python操作YAML文件之pyyaml库

    1. YAML简介 YAML是一种被认为可以超越XML.JSON的配置文件,最早接触是Spring Boot,木有想到python也是支持的,遂研究一下. python解析YAML库叫做pyyaml, ...

  2. 多维尺度变换MDS(Multidimensional Scaling)

    流形学习(Manifold Learning)是机器学习中一大类算法的统称,流形学习是非线性的降维方法(an approach to non-linear dimensionality reducti ...

  3. hdfs的datanode工作原理

    datanode的作用: (1)提供真实文件数据的存储服务. (2)文件块(block):最基本的存储单位.对于文件内容而言,一个文件的长度大小是size,那么从文件的0偏移开始,按照固定的大小,顺序 ...

  4. 关于parse_str变量覆盖分析

    这个漏洞有两个姿势.一个是不存在的时候一个是存在的时候. 经过测试该漏洞只在php5.2中存在,其余均不存在. 倘若在parse_str函数使用的代码上方未将其定义那么即存在变量覆盖漏洞否则不行. 还 ...

  5. 选中一行并且选中该行的radio

    $("tr").bind("click",function(){ $("input:radio").attr("checked&q ...

  6. juery中监听input的变化事件

    $('#searchValue').bind('input propertychange', function() { searchFundList(); });

  7. opencv配置过程 (cmake,vs2013,qt 5.4)

    平台及软件: Windows 7 X86 Visual Studio 2013 OpenCV3.0.0 Cmake3.3 1.下载Windows下的安装文件OpenCV-3.0.0.exe,解压,选择 ...

  8. SSD回归类物体检测

    本宝宝最近心情不会,反正这篇也是搬用别人博客的了:(SSD就是YOLO+anchor(不同feature map 作为input)) 引言 这篇文章是在YOLO[1]之后的一篇文章,这篇文章目前是一篇 ...

  9. VMW虚拟机生成的文件说明

    VMDK(VMWare Virtual Machine Disk Format)是虚拟机VMware创建的虚拟硬格式,文件存在于VMware文件系统中,被称为VMFS(虚拟机文件系统) NVRAM 非 ...

  10. 用OpenSSL命令行生成证书文件

    用OpenSSL命令行生成证书文件 1.首先要生成服务器端的私钥(key文件): openssl genrsa -des3 -out server.key 1024 运行时会提示输入密码,此密码用于加 ...