Codeforces Round #516 (Div. 2)D. Labyrinth
D. Labyrinth
题目链接:https://codeforces.com/contest/1064/problem/D
题意:
给出一个n*m的矩阵以及人物的起点,并且给出x,y,分别代表这个人向左最多走x步,向右最多走y步。
矩阵中存在障碍,问这个人最多能到达多少数量的格子。
题解:
就是一个bfs...只是要稍微剪枝一下,如果发现当前这个点所到达的格子已经被之前的一个点到达过,当且仅当当前点的x或y至少一个比之前到达的点大时,就将这个点入队。
只有这样才能保证解最优。
代码如下:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
const int N = ;
int n,m,R,C;
int mp[N][N],vis[N][N][],l[N][N],r[N][N],check[N][N];
int dx[]={-,,,};
int dy[]={,,,-};
int ans = ;
char s[N];
bool ok(int x,int y){
if(x>= && x<=n && y>= && y<=m && mp[x][y]!=) return true;
return false ;
}
struct node{
int x,y,lx,ly;
}cur;
queue <node> q;
void bfs(){
while(!q.empty()){
node now = q.front();q.pop();
int x = now.x,y = now.y,l,r;
for(int i=;i<;i++){
cur.x=x+dx[i];cur.y=y+dy[i];
l = now.lx;r = now.ly;
if(i==) r--;
if(i==) l--;
if(ok(cur.x,cur.y)&&r>=&&l>=){
if(l>vis[cur.x][cur.y][]||r>vis[cur.x][cur.y][]){
if(vis[cur.x][cur.y][]==-) ans++;
q.push(node{cur.x,cur.y,l,r});
vis[cur.x][cur.y][]=l;
vis[cur.x][cur.y][]=r;
}
}
}
}
}
int main(){
int x,y;
cin>>n>>m>>R>>C>>x>>y;
for(int i=;i<=n;i++){
scanf("%s",s);
for(int j=;j<m;j++){
if(s[j]=='.') mp[i][j+]=;
else mp[i][j+]=;
}
}
q.push(node{R,C,x,y});
memset(vis,-,sizeof(vis));
vis[R][C][]=x;vis[R][C][]=y;
check[R][C]=;
bfs();
cout<<ans;
return ;
}
Codeforces Round #516 (Div. 2)D. Labyrinth的更多相关文章
- Codeforces Round #516 (Div. 2)D. Labyrinth(BFS)
题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最 ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- 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, 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) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
- Codeforces Round #292 (Div. 1)A. Drazil and Factorial 构造
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is play ...
- Codeforces Round #516(Div 2)
比赛链接:传送门 A. Make a triangle!(简单思维) 题目大意: 给你三条边,问你最多加多少长度能使这三条边能构成三角形. 思路: 最大边小于答案加另外两条边的和. #include ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
随机推荐
- OracleWeblogic12C安装教程
一,安装WebLogic Server 1. 双击exe安装文件 2.准备安装文件 3. 生成向导序列 4. 选择安装路径 5. 开始安装 经过以上步骤,weblogic已经成功安装到了你的电脑上,但 ...
- Git版本控制使用方法入门教程
1. 概述 对于软件版本管理工具,酷讯决定摒弃CVS而转向Git了. 为什么要选择Git? 你真正学会使用Git时, 你就会觉得这个问题的回答是非常自然的.然而当真正需要用文字来回答时,却觉得文字好像 ...
- python-7面向对象高级编程
1-给类动态增加方法 class Student(object): pass def set_score(self, score): self.score = score Student.set_sc ...
- 适合pc端的移动拖拽,分享一下。
h5新加的特性拖拽事件,但是只适合PC端哦.不多说了上代码 <!DOCTYPE html> <html> <head> <title></titl ...
- Echarts 背景渐变柱状图
var dom = document.getElementById("container"); var myChart1 = echarts.init(dom); var app ...
- linpack_2
Run linpack in server 1.Get computer nodal information lscpu dmidecode -t memory | head -45 | tail - ...
- Hadoop常用高级特性
HDFS HA HDFS HA(High Availability)高可用性 相同版本拷贝工具,分布式集群拷贝工具,使用MapReduce实现 DistCp Version2 Guide HFTP协议 ...
- The Image Gallery Revisited
Lets apply the Best practices to the Image Gallery . /*** index.html ***/ <!DOCTYPE html> < ...
- 基于CSS多列实现瀑布流
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 8 实现10mins用户登录与注册
1.重新认识登录 2.实现登录功能 (1)Django 自带的authenticate, login模块 from django.contrib.auth import authenticate, l ...