题目链接: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. codeforces 1151 B

    codeforces 1151  B codeforces 1151  B  1600fen 题意:n*m的矩阵,问能否从n行中每行选一个数 异或 大于0 解析:刚开始看没思路,想用dfs跑一遍,看到 ...

  2. Revit二次钢筋

  3. 题解-HAOI2018全套

    去冬令营转了一圈发现自己比别人差根源在于刷题少,见过的套路少(>ω<) 于是闲来无事把历年省选题做了一些 链接放的都是洛谷的,bz偷懒放的也是链接 AM.T1 奇怪的背包 Problem ...

  4. Redis 和 I/O 多路复用

    最近在看 UNIX 网络编程并研究了一下 Redis 的实现,感觉 Redis 的源代码十分适合阅读和分析,其中 I/O 多路复用(mutiplexing)部分的实现非常干净和优雅,在这里想对这部分的 ...

  5. I - Beautiful People ZOJ - 2319 (二分法)

    The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...

  6. Java的慢和稳

    对Java的了解还有待进一步提升,也没有做太多实践工作.只是把脑袋当成电脑,把Java放在里边不停地转,观察它的线路.得到的总体印象加上书本参考,认为Java的应用场景是慢和稳. 学编程语言总会接触到 ...

  7. ELK搭建<二>:安装ES插件head

    1.去github下载head,针对ES版本不同,安装方式也不一样, =>在2.x以前版本可以通过插件安装 for Elasticsearch 2.x: sudo elasticsearch/b ...

  8. mysql函数取出单个字段重新组成一维数组

    array_column():

  9. [转] 2017-11-20 发布 另辟蹊径:vue单页面,多路由,前进刷新,后退不刷新

    目的:vue-cli构建的vue单页面应用,某些特定的页面,实现前进刷新,后退不刷新,类似app般的用户体验.注: 此处的刷新特指当进入此页面时,触发ajax请求,向服务器获取数据.不刷新特指当进入此 ...

  10. Intellij IDEA 从数据库生成 JPA Entity

    首先,需要从调用 Database 窗口 View>Tool Windows>Database 添加到数据库的连接 选择数据的表,然后右击 选择 Scripted Extensions & ...