[Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]
题目链接:1063B - Labyrinth/1064D - Labyrinth
题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x\)和\(y\),给出起点并询问有多少个点能够到达。
题解:此题坑多...本弱写裸BFS,WA了一百次_(:з」∠)_
考虑从点\(A\)到点\(B\)需要向左或者向右走的次数,可以发现若设向左走的次数为\(l\),向右走的次数为\(r\),则\(r-l\)是个定值,因此转换成最短路问题用最短路跑一遍就好了。
#include<bits/stdc++.h>
using namespace std;
#define N 2001
#define INF 1000000007
int n,m,r,c,A,B,f[N][N],ans;
struct rua{int x,y;};
struct res
{
int a,b;
res operator +(const res &t)const{return {a+t.a,b+t.b};}
bool operator <(const res &t)const{return a!=t.a?a<t.a:b<t.b;}
bool operator <=(const res &t)const{return a<=t.a && b<=t.b;}
}dis[N][N];
bool vis[N][N];
queue<rua>q;
int get()
{
char ch=getchar();
while(ch!='.' && ch!='*')
ch=getchar();
return ch=='.';
}
int main()
{
scanf("%d%d%d%d%d%d",&n,&m,&r,&c,&A,&B);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
f[i][j]=get(),dis[i][j]={INF,INF};
dis[r][c]={,};
q.push({r,c}),vis[r][c]=true;
while(!q.empty())
{
rua cur=q.front();q.pop();
int x=cur.x,y=cur.y;
vis[x][y]=false;
if(x> && f[x-][y] && dis[x][y]<dis[x-][y])
{dis[x-][y]=dis[x][y];if(!vis[x-][y])q.push({x-,y}),vis[x-][y]=true;}
if(x<n && f[x+][y] && dis[x][y]<dis[x+][y])
{dis[x+][y]=dis[x][y];if(!vis[x+][y])q.push({x+,y}),vis[x+][y]=true;}
if(y> && f[x][y-] && dis[x][y]+(res){,}<dis[x][y-])
{dis[x][y-]=dis[x][y]+(res){,};if(!vis[x][y-])q.push({x,y-}),vis[x][y-]=true;}
if(y<m && f[x][y+] && dis[x][y]+(res){,}<dis[x][y+])
{dis[x][y+]=dis[x][y]+(res){,};if(!vis[x][y+])q.push({x,y+}),vis[x][y+]=true;}
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(dis[i][j]<=res{A,B})
ans++;
return printf("%d\n",ans),;
}
[Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]的更多相关文章
- [Codeforces Round #516][Codeforces 1063C/1064E. Dwarves, Hats and Extrasensory Abilities]
题目链接:1063C - Dwarves, Hats and Extrasensory Abilities/1064E - Dwarves, Hats and Extrasensory Abiliti ...
- Codeforces Round #516 (Div. 2)D. Labyrinth
D. Labyrinth 题目链接:https://codeforces.com/contest/1064/problem/D 题意: 给出一个n*m的矩阵以及人物的起点,并且给出x,y,分别代表这个 ...
- Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...
- Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth
http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k ...
- Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth(重识搜索)
https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y ...
- Codeforces Round #516 (Div. 2) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
- Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)
题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #defin ...
- Codeforces Round #516(Div 2)
比赛链接:传送门 A. Make a triangle!(简单思维) 题目大意: 给你三条边,问你最多加多少长度能使这三条边能构成三角形. 思路: 最大边小于答案加另外两条边的和. #include ...
- CodeForces Round #516 Div2 题解
A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...
随机推荐
- centos7 搭建jenkins服务器
具体可参考:https://blog.csdn.net/it_lihongmin/article/details/80814384 注意: 1. 修改主目录:默认是/var/lib/jenkins, ...
- L2-007 家庭房产 (25 分) (并查集)
链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805068539215872 题目: 给定每个人的家庭成员和其自己名 ...
- Win 10中使用图片查看器
在Win10中,照片应用提供了时间线.专辑等更丰富的图片管理功能,但是对于基于文件夹打开浏览图片的方式显得笨拙, 放大缩小操作略繁琐,有时还会出现当前文件夹图片加载迟缓导致无法快速浏览的问题. 此时你 ...
- 增加swap分区
起因:开发人员说tomcat关闭了,然后我排查了下,发现内存耗尽,然后临时用swap分区,以供当前运行的程序使用. 先用free -h查看一下swap的大小 1.添加swap分区 使用dd命令创建/h ...
- Gitlab_ansible_jenkins三剑客③Ansible的安装及使用
一台服务器可能会安装不同的python应用,不同的应用可能使用的模块版本不同,如果都安装在同样的环境下容易冲突,为了避免冲突,引入virtualenv 这个包管理工具进行环境的隔离 使用pip安装之前 ...
- 收藏一个可以学习javascript prototype的链接
https://github.com/mqyqingfeng/Blog/issues/2
- 设计模式 — 单例模式(Singleton)
在一个软件系统中,经常有有些特殊的对象就需要一个实例,如果有多个的话,就比较浪费服务器资源,最典型的就是 整个系统的配置文件对象. 普通方式读取配置文件 // 配置文件 SingletonApp.pr ...
- elsticsearch在kibanna中的操作
#建立索引 PUT /es_note_tel{ "settings": { "number_of_shards": 1 }, "mappings&qu ...
- JsonIgnore注解不起作用的解决办法
一开始在属性上注解了JsonIgnore以为就不会序列化了,结果还是有这个属性,看来是没有起作用啊 [JsonIgnore] public List<int> SubjectAndSubS ...
- Jenkins Vue项目自动构建以及构建后续操作
Jenkins在linux上的安装教程:http://www.ityouknow.com/springboot/2017/11/11/springboot-jenkins.html 另外,关于在win ...