CodeForces 1063B. Labyrinth 性质
给定$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 性质的更多相关文章
- 【非原创】codeforces 1063B Labyrinth 【01bfs】
学习博客:戳这里 附本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 co ...
- [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]
题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...
- Codeforces 1064D/1063B Labyrinth
原题链接/原题链接(代理站) 题目翻译 给你一个\(n*m\)的迷宫和起始点,有障碍的地方不能走,同时最多向左走\(x\)次,向右走\(y\)次,向上向下没有限制,问你有多少个格子是可以到达的. 输入 ...
- 【Codeforces 1063B】Labyrinth
[链接] 我是链接,点我呀:) [题意] 你可以往左最多x次,往右最多y次 问你从x,y出发最多能到达多少个格子 只能往上下左右四个方向走到没有障碍的格子 [题解] 假设我们从(r,c)出发想要到固定 ...
- Codeforces 1142A(性质、暴举)
队友和大佬都什么几种情况啥的……我是把终点都插了,起点随便选一个,暴举答案莽A. ; ll n, k, a, b, aa, minn = INF, maxx = -; set<ll> bb ...
- CF 1063B Labyrinth
传送门 解题思路 看上去很简单,\(bfs\)写了一发被\(fst\)...后来才知道好像一群人都被\(fst\)了,这道题好像那些每个点只经过一次的传统\(bfs\)都能被叉,只需要构造出一个一块一 ...
- Codeforces 1064D Labyrinth(双端队列BFS)
题意: 给一个图,"*"不可以走,给你一个起点,限制向左走L次,向右走R次,上下不限制,问你最多可以走到多少个格子 思路: BFS,每次将上下走的策略加入队首,左右加入队尾,(相当 ...
- 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 ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
随机推荐
- vue-router.esm.js?fe87:16 [vue-router] Route with name 'page' does not exist
本文地址:http://www.cnblogs.com/veinyin/p/7910525.html 我的路由配置 { path: '/page', name: page, component: pa ...
- HDU 1256 画8 (找规律)
题目链接 Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中 ...
- 【C++自我精讲】基础系列六 PIMPL模式
[C++自我精讲]基础系列六 PIMPL模式 0 前言 很实用的一种基础模式. 1 PIMPL解释 PIMPL(Private Implementation 或 Pointer to Implemen ...
- 离散化&&逆序数对
题目:http://www.fjutacm.com/Problem.jsp?pid=3087 #include<stdio.h> #include<string.h> #inc ...
- 一个JAVA渣渣的校招成长记,附BAT美团网易等20家面经总结
欢迎关注我的微信公众号:"Java面试通关手册"(坚持原创,分享美文,分享各种Java学习资源,面试题,以及企业级Java实战项目回复关键字免费领取): 今天分享一篇牛客网上的一个 ...
- for 、forEach 、 forof、 forin遍历对比
一.遍历内容的异同 1.for 和 for...in 是针对数组下标的遍历 2.forEach 及 for...of 遍历的是数组中的元素 二.对非数字下标的处理 由于array在js中也是对象中的一 ...
- php 7.3.3安装问题记录
1.checking for libzip... not foundconfigure: error: Please reinstall the libzip distribution 参考:http ...
- 5.Python3标准库-日期和时间
''' 不同于int,str,float,Python没有包含对应日期和时间的原生类型,不过提供了3个相应的模块,可以采用多种表示来管理日期和时间值 time模块由底层C库提供与时间相关的函数.它包含 ...
- acm专题---最小生成树
kruscal(eloge): 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Problem Description There are N ...
- Caffe学习系列(8):solver,train_val.prototxt,deploy.prototxt及其配置
solver是caffe的核心. net: "examples/mnist/lenet_train_test.prototxt" test_iter: 100 test_inter ...