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 ...
随机推荐
- Selenium 3----控制浏览器操作
控制浏览器窗口大小 eg:将浏览器设置成移动端大小(480*800),进行访问 set_window_size()方法: from selenium import webdriver driver=w ...
- WebH
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- [No0000197]Windows用户都应该知道的运行命令
通过"运行"命令,运行Windows丰富工具的方法.如果您知道工具或任务的相应"运行"命令,那么您就知道访问所述工具或任务的最快方法. 以下是我们最喜欢的Run ...
- 【模拟与阅读理解】Gym - 101954C Rullete
http://codeforces.com/gym/101954/problem/C 题意:14行伪代码让你翻译. 坑得yibi #include<stdio.h> #include< ...
- 实现mybash
任务内容 1.使用fork,exec,wait实现mybash 查找资料: fork函数 通过fork()系统调用我们可以创建一个和当前进程印象一样的新进程.我们通常将新进程称为子进程,而当前进程称为 ...
- Micro和Macro性能学习【转载】
转自:https://datascience.stackexchange.com/questions/15989/micro-average-vs-macro-average-performance- ...
- 转载 Unity Text 插入超链接
using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressi ...
- Java IO--BIO
一.java io 概述 1.1 相关概念 Java IO Java IO即Java 输入输出系统.不管我们编写何种应用,都难免和各种输入输出相关的媒介打交道,其实和媒介进行IO的过程是十分复杂的,这 ...
- .Net 多线程 (1) Task
多线程是一种有效提高程序工作效率的方法.当然为了效率需要使用更多的cpu,内存等资源. 并发是两个队列交替使用一台咖啡机,并行是两个队列同时使用两台咖啡机,如果串行,一个队列使用一台咖啡机,那么哪怕前 ...
- sitecore 数字化营销-path funnel
路径分析器是一个应用程序,允许您查看联系人在浏览网站时所采用的各种路径.您可以查看联系人在转换目标并与广告系列互动时所采用的路径,让您深入了解哪些路径为每次转化提供最佳参与价值,以及哪些路径效率较低且 ...