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 ...
随机推荐
- 始终要重载toString
本文涉及到的概念 1.重载toString方法的意义 2.两个注意事项 1.重载toString方法的意义 重载toString,返回关于当前实例的描述信息.这在调试错误,打印实例信息时,可以带来 ...
- 数据库-SQLite
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong 数据库-SQLite 技术博客http:// ...
- jQuery.Event的一些用法
直接写用法 //创建一个事件 var event = $.Event("事件类型",["定义的事件参数最终将出现在e1中"]); //绑定一个处理器 $(obj ...
- typeof运算符
javascript中typeof用来判断一个变量或表达式的数据类型. typeof 返回值有六种可能: "number," "string," "b ...
- php的发展历史
php最初就是为了快速构建一个web页面而迅速被大家广为接受的.它的好处是在代码中能内嵌html的代码,从而让程序员能再一个页面中同时写html代码和php代码就能生成一个web页面. 这篇文章用时间 ...
- (4)剑指Offer之链表相关编程题
一 链表中倒数第k个节点 题目描述: 输入一个链表,输出该链表中倒数第k个结点 问题分析: 一句话概括: 两个指针一个指针p1先开始跑,指针p1跑到k-1个节点后,另一个节点p2开始跑,当p1跑到最后 ...
- java的loadrunner脚本案例
/* * LoadRunner Java script. (Build: 670) * * ״̬£º²¢·¢²âÊÔͨ¹ý * ²âÊÔÈË£ºÕÔС±ò * ÈÕÆÚ£º2013-09-2 ...
- 13.Python3标准库--互联网
(一)urllib.parse:分解url urllib.parse模块提供了一些函数,可以管理URL以及组成部分 1.解析 from urllib.parse import urlparse ''' ...
- java版云笔记(三)
登录与注册写好了下来就是主页,今天写的是主页加载时笔记本列表的显示,ajax是固定的就不重点说了.主要说一下jQuery.data() 函数和jQuery.on() 函数. 注:这个项目的sql文件, ...
- LightOJ - 1010 Knights in Chessboard(规律)
题目链接:https://vjudge.net/contest/28079#problem/B 题目大意:给你一个nxm的棋盘,问你最多可以放几个骑士让他们互相攻击不到.骑士攻击方式如下图: 解题思路 ...