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 ...
随机推荐
- [csp-201809-3]元素选择器-编译原理
声明:同样是参考照抄hyh学长的代码!(有问题我马上删这篇emm 题目链接:http://118.190.20.162/view.page?gpid=T77 题面: 这棵树的样子(同样是来自学长的图) ...
- 第5堂音频课:发音&词串&自学方法示范
1. 发音怎么练习 我讲解的第5-6节发音课,就像一个有用教练,教你的划水姿势,你学了以后,在床上趴着练练蹬腿,然后,要立刻跳下水去游泳,也就是说,你要去听英语: 请你听一段可可宝贝APP的绘本故事, ...
- git 还原到指定版本号
git clone git branch -r --contains 88b92060224e96ef209565fa75c816eb9b0fae8e git checkout origin/re ...
- BZOJ 1975: [Sdoi2010]魔法猪学院——K短路,A*
传送门 http://www.lydsy.com/JudgeOnline/problem.php?id=1975 题意&简要做法 一张有向图,求出最多的互不相同的路径,满足路径长度之和\(\l ...
- ftp--vsftp\pureftpd
FTP是File Transfer Protocol(文件传输协议),用于Internet上的控制文件的双向传输. 现今常用在一个局域网内,如学校.公司等一个指定范围的区域.(因为太过于简单和不安全) ...
- MySQL 视图、触发器、函数、存储过程
1. 视图 1.1 什么是视图 通俗来讲,视图就是一条 select 语句执行后返回的结果集.所有我们在创建视图的时候,主要的工作就落在创建这条SQL查询语句上. 1.2 视图的特性 视图是对若干张基 ...
- HDU 4553 约会安排(线段树区间合并+双重标记)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4553 题目大意:就是有三种操作: ①DS x,安排一段长度为x的空闲时间跟屌丝一起,输出这段时间的起点 ...
- 转载--void指针(void *的用法)
转自:jimmy 指针有两个属性:指向变量/对象的地址和长度 但是指针只存储地址,长度则取决于指针的类型 编译器根据指针的类型从指针指向的地址向后寻址 指针类型不同则寻址范围也不同,比如: int*从 ...
- jq用户评论点击回复简单代码。
类似这种镶套回复评论: <div> <ul> <!--一条评论 begin--> <li> <div class="user-colum ...
- 使用jdk自带的工具native2ascii 转换Unicode字符和汉字
1.控制台转换 1.1 将汉字转为Unicode: C:\Program Files\Java\jdk1.5.0_04\bin>native2ascii 测试 \u6d4b\u8bd5 1.2 ...