Codeforces 1064 D - Labyrinth
对于位置(i,j), j - c = R - L = const(常数), 其中R表示往右走了几步,L表示往左走了几步
所以R越大, L就越大, R越小, L就越小, 所以只需要最小化L和R中的其中一个就可以了
由于每次变化为0或1,所以用双端队列写bfs, 保证最前面的值最小, 简化版的dijkstra
不过看到好多没写双端队列的也过了......
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e3 + ;
char s[N][N];
int mnr[N][N];
int dir[][] = {, , , , -, , , -};
deque<piii> q;
int n, m;
void bfs(int x, int y, int rx, int ry) {
mem(mnr, 0x3f);
mnr[x][y] = ;
q.push_back({{x, y}, });
while(!q.empty()) {
piii p = q.front();
q.pop_front();
for (int i = ; i < ; i++) {
int xx = p.fi.fi + dir[i][];
int yy = p.fi.se + dir[i][];
if(i == ) {
if( <= xx && xx <= n && <= yy && yy <= m && s[xx][yy] == '.' && p.se + < mnr[xx][yy]) {
mnr[xx][yy] = p.se+;
q.push_back({{xx, yy}, p.se+});
}
}
else {
if( <= xx && xx <= n && <= yy && yy <= m && s[xx][yy] == '.' && p.se < mnr[xx][yy]) {
mnr[xx][yy] = p.se;
q.push_front({{xx, yy}, p.se});
}
}
}
}
}
int main() {
int r, c, x, y;
scanf("%d %d", &n, &m);
scanf("%d %d", &r, &c);
scanf("%d %d", &x, &y);
for (int i = ; i <= n; i++) scanf("%s", s[i]+);
int ans = ;
bfs(r, c, x, y);
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
int cst = j - c;
int l = mnr[i][j] - cst;
if(mnr[i][j] <= y && l <= x) ans++;
}
}
printf("%d\n", ans);
return ;
}
Codeforces 1064 D - Labyrinth的更多相关文章
- CF 1064 D. Labyrinth
D. Labyrinth http://codeforces.com/contest/1064/problem/D 题意: n*m的矩阵,只能往左走l次,往右走r次,上下走无限制,问能走到多少个点. ...
- [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]
题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...
- CodeForces 616C The Labyrinth
先预处理出所有连通块,对于每一个*,看他四周的连通块即可 #include<cstdio> #include<cstring> #include<queue> #i ...
- codeforces 1064套题
a题:题意就是问,3个数字差多少可以构成三角形 思路:两边之和大于第三遍 #include<iostream> #include<algorithm> using namesp ...
- Codeforces 1064D/1063B Labyrinth
原题链接/原题链接(代理站) 题目翻译 给你一个\(n*m\)的迷宫和起始点,有障碍的地方不能走,同时最多向左走\(x\)次,向右走\(y\)次,向上向下没有限制,问你有多少个格子是可以到达的. 输入 ...
- [ CodeForces 1063 B ] Labyrinth
\(\\\) \(Description\) 给出一个四联通的\(N\times M\) 网格图和起点.图中有一些位置是障碍物. 现在上下移动步数不限,向左至多走 \(a\) 步,向右至多走 \(b\ ...
- [ CodeForces 1064 B ] Equations of Mathematical Magic
\(\\\) \(Description\) \(T\) 组询问,每次给出一个 \(a\),求方程 \[ a-(a\oplus x)-x=0 \] 的方案数. \(T\le 10^3,a\le 2^{ ...
- 【Codeforces 1063B】Labyrinth
[链接] 我是链接,点我呀:) [题意] 你可以往左最多x次,往右最多y次 问你从x,y出发最多能到达多少个格子 只能往上下左右四个方向走到没有障碍的格子 [题解] 假设我们从(r,c)出发想要到固定 ...
- Codeforces Round #516 (Div. 2) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
随机推荐
- vim-cscope插件
在工程根目录生成cscope.out 索引文件的脚本 rm -f cscope* currentPath=$(pwd ) echo $currentPath find $currentPath -na ...
- xcode工程编译错误之iOS解决CUICatalog: Invalid asset name supplied问题
[问题分析]: 这个问题其实是老问题,产生原因就是因为在使用的时候 [UIImage imageNamed:]时,图片不存在或者传入的图片名为nil. [解决方法]: 添加一个系统断点,来判断如果图片 ...
- Swagger学习笔记
狂神声明 : 文章均为自己的学习笔记 , 转载一定注明出处 ; 编辑不易 , 防君子不防小人~共勉 ! Swagger学习笔记 课程目标 了解Swagger的概念及作用 掌握在项目中集成Swagger ...
- 图->最短路径->多源最短路径(弗洛伊德算法Floyd)
文字描述 求每一对顶点间的最短路径,可以每次以一个顶点为源点,重复执行迪杰斯特拉算法n次.这样,便可求得每一对顶点之间的最短路径.总的执行时间为n^3.但是还有另外一种求每一对顶点间最短路径的方法,就 ...
- 解决端口耗尽问题: tcp_tw_reuse、tcp_timestamps
一.本地端口有哪些可用 首先,需要了解到TCP协议中确定一条TCP连接有4要素:local IP, local PORT, remote IP, remote PORT.这个四元组应该是唯一的. 在我 ...
- MVC中code first方式开发,数据库的生成与更新
在使用EF的实际编程中我们经常遇到这样的问题:发现实体结构需要新增加一个字段,或者减少一个字段,急需把实体结构修改,并让数据库更新这种修改.在用Model First或者Database First的 ...
- Fiddler修改图片显示
培训课讲修改请求值,记录一下操作步骤: 步骤如下: 1. 点击人人网图片另存为到桌面 2. 打开fiddler,找到图片发送的请求(单击图片的链接,点击右边面板的Inspectors.查看ImageV ...
- golang schedule crash
golang 起超过100W的goroutine就会crash,这个算不算是个bug? 2036119xxxxpanic: inconsistent poll.fdMutex goroutine 20 ...
- 运行pytorch代码遇到的error解决办法
1.no CUDA-capable device is detected 首先考虑的是cuda的驱动问题,查看gpu显示是否正常,然后更新最新的cuda驱动: 第二个考虑的是cuda设备的默认参数是否 ...
- python模块的学习
# time 模块 import time print(time.time()) #当前的时间挫 #time.sleep(3) #休息3秒钟,这3秒cpu不工作的 print(time.gmtime( ...