[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 ...
随机推荐
- referrer policy
我们知道,在页面引入图片.JS 等资源,或者从一个页面跳到另一个页面,都会产生新的 HTTP 请求,浏览器一般都会给这些请求头加上表示来源的 Referrer 字段.Referrer 在分析用户来源时 ...
- 项目Alpha冲刺(1/10)
1.项目燃尽图 2.今日进度描述 项目进展 熟悉Android Studio的基本使用,阅读代码规范 问题困难 学习中存在许多问题. 心得体会 应该选择一个自己熟悉的平台进行开发. 3.会议照片 4. ...
- 使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium)
抖音很火,楼主使用python随机爬取抖音视频,并且无水印下载,人家都说天下没有爬不到的数据,so,楼主决定试试水,纯属技术爱好,分享给大家.. 1.楼主首先使用Fiddler4来抓取手机抖音app这 ...
- 有名的素MM
from math import sqrt item=[] for yr in [1988,1989]: for mth in range(1,13): if mth in [1,3,5,7,8,10 ...
- 基于python的WGS84转百度坐标
from urllib.request import urlopen, quote import json def wgs84tobaidu(x,y): data=str(x)+','+str(y); ...
- Python爬取指定重量的快递价格
目录 一.获取查询接口 二.获取相关数据 三.编写爬虫脚本 四.查看查询效果 背景:现在这个时代,快递横飞.我们想寄一个快递,给出的选择也是多种多样的(根据快递的大小.送达的时间.寄送的距离及价格.公 ...
- Calendar日历工具类
这个工具类有效的避免跨年的问题 先定义一个日期格式类型: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:s ...
- Spring Session产生的sessionid与cookies中的sessionid不一样的问题 && httpOnly 设置不起作用的问题??
背景: Springboot 2.0 (spring-session-data-redis + spring-boot-starter-web) 需求: 通过cookies中取到的 sessionid ...
- 运行Scrapy程序时出现No module named win32api问题的解决思路和方法
有小伙伴在群里边反映说在使用Scrapy的时候,发现创建项目一切顺利,但是在执行Scrapy爬虫程序的时候却出现下列报错:“No module named win32api”,如下图所示,但是不知道怎 ...
- 安装SSL证书 and 根域名跳转www域名
1.安装自签证书 自签证书也就是不被公网认可的证书,可在局域网内进行签名认证,其12306也是自签证书,通过证书+nginx代理web服务器 可以实现https连接 一.使用OpenSSL创建证书 ...