题目链接: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]的更多相关文章

  1. [Codeforces Round #516][Codeforces 1063C/1064E. Dwarves, Hats and Extrasensory Abilities]

    题目链接:1063C - Dwarves, Hats and Extrasensory Abilities/1064E - Dwarves, Hats and Extrasensory Abiliti ...

  2. Codeforces Round #516 (Div. 2)D. Labyrinth

    D. Labyrinth 题目链接:https://codeforces.com/contest/1064/problem/D 题意: 给出一个n*m的矩阵以及人物的起点,并且给出x,y,分别代表这个 ...

  3. Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)

    题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...

  4. 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 ...

  5. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth(重识搜索)

    https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y ...

  6. Codeforces Round #516 (Div. 2) (A~E)

    目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...

  7. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

    题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #defin ...

  8. Codeforces Round #516(Div 2)

    比赛链接:传送门 A. Make a triangle!(简单思维) 题目大意: 给你三条边,问你最多加多少长度能使这三条边能构成三角形. 思路: 最大边小于答案加另外两条边的和. #include ...

  9. CodeForces Round #516 Div2 题解

    A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...

随机推荐

  1. springboot整合springdata-jpa

    1.简介  SpringData : Spring 的一个子项目.用于简化数据库访问,支持NoSQL 和 关系数据存储.其主要目标是使数据库的访问变得方便快捷. SpringData 项目所支持 No ...

  2. anylogic 常用模块及术语的使用

    1.1 存量 创建存量变量 1. 在调色板视图下的Model页面中选择Stock 元素. 2. 在图形化编辑器中您所期望的位置点击鼠标,放置该存量. 3. 在属性视图下的Equation部分中,定义该 ...

  3. OSG开源教程(转)

    例:geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); 来指定要利用这些数据生成一个怎么样的形状. ...

  4. stylus 实践

    音乐分享: Broken Back - <Halcyon Birds> —————————————————————————————————————————————————————————— ...

  5. HTML 动画收藏

    各种loading图标动画 http://www.yyyweb.com/377.html http://www.yyyweb.com/350.html

  6. java程序设计第二次作业

  7. php 获取用户的IP、地址、来源

    js方法获取用户的 ip 和 地址 <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> ...

  8. Justoj 2388最短区间 贪心

    2388: 最短区间 Time Limit: 1 s      Memory Limit: 128 MB Submit My Status Problem Description 有M种不同颜色的气球 ...

  9. Hive 2.1.1 学习笔记

    1.修改conf下的配置文件cp -a hive-default.xml.template hive-site.xml2.进入bin目录启动hive./hive 报错Exception in thre ...

  10. JavaScript复制文本探究

    JS复制文本基本分为两步-First: 选中需要复制的节点,及选区:Second: 执行document.execCommand('copy')命令复制 对于选区,属于HTMLInputElement ...