题目链接: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),;
}

最新文章

  1. mybatis常见易出错
  2. C#算法知识点记录
  3. VS工程添加资源文件
  4. Android4.4 往短信收件箱中插入自定义短信(伪造短信)
  5. EF 中更新模型的问题,这种错误(因为相同类型的其他实体已具有相同的主键值。)
  6. 关于WCF一些基础。
  7. 精确覆盖DLX算法模板另一种写法
  8. js模块化开发——require.js学习总结
  9. 用Nodejs做一个简单的小爬虫
  10. php中的多条件查询
  11. Python3 SMTP发送邮件
  12. ASP.NET实现二维码
  13. 一键发布部署vs插件[AntDeploy]开源了
  14. JAVA 求数组中的最大值
  15. php 带省略号的分页
  16. 20145318《网络对抗》注入shellcode及Return-to-libc
  17. 51nod 1266 蚂蚁
  18. NOSQL详解
  19. 算法:QQ等级换算成皇冠太阳星星月亮
  20. 使用baksmali及smali修改apk并打包

热门文章

  1. Linux 使用 arp-scan 检查是否存在IP地址冲突
  2. P5303 [GXOI/GZOI2019]逼死强迫症
  3. 20175315Mycp
  4. zabbix3.2利用自动发现功能对fastcgi模式的php状态进行集中监控
  5. C# windows定时服务+服务邮箱发送
  6. Maven项目引入log4j的详细配置
  7. 金山WPS一面
  8. IBOS二次开发之视图创建(PHP技术)
  9. disconf使用小结
  10. SVM:根据大量图片来精确实现人脸识别—Jason niu