codeforces Labyrinth


codeforces Labyrinth

  Time Limit: 2 Sec
  Memory Limit: 512 MB

Description

   You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if the target cell is not occupied by an obstacle. You can't move beyond the boundaries of the labyrinth.
   Unfortunately, your keyboard is about to break, so you can move left no more than x times and move right no more than y times. There are no restrictions on the number of moves up and down since the keys used to move up and down are in perfect condition.
   Now you would like to determine for each cell whether there exists a sequence of moves that will put you from the starting cell to this particular one. How many cells of the board have this property?
 

Input

   The first line contains two integers \(n, m (1 ≤ n, m ≤ 2000)\) — the number of rows and the number columns in the labyrinth respectively.
   The second line contains two integers \(r, c (1 ≤ r ≤ n, 1 ≤ c ≤ m)\) — index of the row and index of the column that define the starting cell.
   The third line contains two integers \(x, y (0 ≤ x, y ≤ 10^9)\) — the maximum allowed number of movements to the left and to the right respectively.
   The next n lines describe the labyrinth. Each of them has length of m and consists only of symbols '.' and ''. The \(j\)-th character of the \(i\)-th line corresponds to the cell of labyrinth at row i and column \(j\). Symbol '.' denotes the free cell, while symbol '' denotes the cell with an obstacle.
   It is guaranteed, that the starting cell contains no obstacles.
 

Output

   Print exactly one integer — the number of cells in the labyrinth, which are reachable from starting cell, including the starting cell itself.
 

Sample Input 1

   \(4\) \(5\)
   \(3\) \(2\)
   \(1\) \(2\)
   \(.....\)
   \(.***.\)
   \(...**\)
   \(*....\)
 

Sample Output 1

  \(10\)
    

Sample Input 2

   \(4\) \(4\)
   \(2\) \(2\)
   \(0\) \(1\)
   \(....\)
   \(..*.\)
   \(....\)
   \(....\)
  

Sample Output 2

  \(7\)
    

HINT

  Cells, reachable in the corresponding example, are marked with '+'.
  
  First example:
  \(+++..\)
  \(+***.\)
  \(+++**\)
  \(*+++.\)
  Second example:
  \(.++.\)
  \(.+*.\)
  \(.++.\)
  \(.++.\)
  

题目地址:codeforces Labyrinth

题目大意:

  读入一个 \(n*m\) 的图起点为 \((r,c)\)
  最多可以向左走 \(x\) 步,向右走 \(y\)
  问可以到那些点

题解:

  解法一 \((Dijkstra)\)
  从一个点到另一个点横向走的步数 \(x\) 和纵向走的步数 \(y\)
  \(x-y\) 为定值
  所以对于一个点,我们只要向左右任意一个方向建一条距离为 \(1\) 的边,其余三个方向都建距离为 \(0\) 的边,然后跑 \(Dijkstra\) 就好了,最后时候算一下要向左向右走几步判一下就好了
  解法二 \((deque)\)
  考试的时候写了最暴力的 \(bfs ......\)
  因为可能会先做花一些代价的方案到某一个点而把不用花代价的方案给排掉了
  所以我们可以每次把不用花代价的方案放到队首,把花代价的放到队尾
  每次从队首取点,就写完了
  orz大神们


AC代码

#include <cstdio>
#include <deque>
using namespace std;
const int N=2005;
int n,m,R,C,x,y,ans;
char ch[N][N];
bool vis[N][N];
struct note{int x,y,a,b;
};
deque<note> q;
int main(){scanf("%d%d",&n,&m);scanf("%d%d",&R,&C);scanf("%d%d",&x,&y);for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);q.push_back((note){R,C,x,y});while(!q.empty()){note tmp=q.front();q.pop_front();int x=tmp.x,y=tmp.y;if(vis[x][y])continue;vis[x][y]=1;ans++;if(1<=x-1 && ch[x-1][y]=='.')q.push_front((note){x-1,y,tmp.a,tmp.b});if(x+1<=n && ch[x+1][y]=='.')q.push_front((note){x+1,y,tmp.a,tmp.b});if(1<=y-1 && ch[x][y-1]=='.' && tmp.a)q.push_back((note){x,y-1,tmp.a-1,tmp.b});if(y+1<=m && ch[x][y+1]=='.' && tmp.b)q.push_back((note){x,y+1,tmp.a,tmp.b-1});}printf("%d\n",ans);return 0;
}


  作者:skl_win
  出处:https://www.cnblogs.com/shaokele/
  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

转载于:https://www.cnblogs.com/shaokele/p/9791063.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/367003.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在vscode使用editorconfig的正确姿势

editorconfig是什么鬼&#xff1f; editorconfig是用来帮助开发者定义和维护代码风格&#xff08;行尾结束符、缩进风格等&#xff09;的东东。 editorconfig支持哪些规则&#xff1f; 请自行参考 https://editorconfig.org/ 如何在vscode中使用editorconfig&#xff1f; 在…

使用Java的Apache Camel入门

Apache Camel是一个非常有用的库&#xff0c;可以帮助您处理来自许多不同来源的事件或消息。 您可以通过许多不同的协议&#xff08;例如在VM&#xff0c;HTTP&#xff0c;FTP&#xff0c;JMS甚至DIRECTORY / FILE之间&#xff09;移动这些消息&#xff0c;但仍使处理代码不受传…

Mvc+Hui+SqlSugar+Autofac+NLog+T4 架构设计(一)

一、前言 作为小菜鸟第一次写博客的我还有点小激动&#xff0c;最近开始打算着手写一个属于自己架构。算下来差不多最近花一周多的下班时间了来写这个框架&#xff0c;本来想整体架构开发完成测试完成后才写博客&#xff0c;怕自己没时间或失去动力&#xff0c;就先把自己架构设…

闲话杂谈—至曾经的自己

【这篇闲话杂谈写的背景时间是&#xff1a;2018年9月30号】 今天估计是自己突然灵光一闪&#xff0c;又或许是想到昨天团建时曾经带自己的师傅&#xff08;刘工&#xff09;的一番话。让我觉得大家都在变化&#xff0c;都慢慢的不再是曾经咱们一块儿奋斗、一块儿无话不谈&#…

房价在手,天下我有 --反手就撸一个爬虫(终)

接上篇&#xff0c;科科&#xff0c;好&#xff0c;我们继续 我们在这里先把json数据入库吧&#xff5e; 首先&#xff0c;database/scheme里定义好数据类型。 const mongoose require(mongoose)const detailHouseSchema new mongoose.Schema({ //定义数据模式link:String…

1.1 计算机网络的形成和发展

1.早期计算机网络&#xff1a;20世纪60年代前 计算机和通信技术结合的先驱&#xff1a;SAGE半自动化地面防空系统 &#xff0c;该系统由麻省理工学院林肯实验室设计。 计算机通信在民用领域的代表&#xff1a;飞机订票系统SABRE-I &#xff0c;美国航空公司与IBM公司联合开发。…

Spring MVC:带有CNVR卷的REST应用程序。 1个

不久前&#xff0c;我阅读了Paul Chapman撰写的有关内容协商视图解析器 &#xff08;CNVR&#xff09;的文章。 Spring Framework Blog上的那篇文章启发了我研究这个框架的领域。 因此&#xff0c;我开发了一个基于Spring MVC和CNVR的 REST示例应用程序。 该应用程序演示了REST…

《精通Spring 4.x 企业应用开发实战》学习笔记

第四章 IoC容器 4.1 IoC概述 IoC&#xff08;Inverse of Control 控制反转&#xff09;&#xff0c;控制是指接口实现类的选择控制权&#xff0c;反转是指这种选择控制权从调用类转移到外部第三方类或容器的手中。 也就是由Spring容器借由Bean配置来进行控制。 DI&#xff08;D…

微前端——无界wujie

B站课程视频 课程视频 课程课件笔记&#xff1a; 1.微前端 2.无界 现有的微前端框架&#xff1a;iframe、qiankun、Micro-app&#xff08;京东&#xff09;、EMP&#xff08;百度&#xff09;、无届 前置 初始化 新建一个文件夹 1.通过npm i typescript -g安装ts 2.然后可…

java executor spring_Spring+TaskExecutor实例

一 TaskExecutor接口Spring的TaskExecutor接口等同于Java.util.concurrent.Executor接口。 实际上&#xff0c;它存在的主要原因是为了在使用线程池的时候&#xff0c;将对Java 5的依赖抽象出来。 这个接口只有一个方法execute(Runnable task)&#xff0c;它根据线程池的语义和…

小程序居然可以用WXS模拟实现过滤器!

小程序目前官方还没有出过滤器&#xff0c;特别不方便&#xff0c;但是可以用wxs来模拟过滤器&#xff0c;话不多说&#xff0c;直接上代码。当然&#xff0c;不熟悉wxs的可以先看一下 官方文档 1.新建一个filter.wxs的文件我个人建议是一个过滤器写一个wxs&#xff0c;避免引用…

ADF:使用HTTP POST方法进行URL任务流调用

众所周知&#xff0c;可以通过某些URL直接从浏览器或某些外部应用程序调用有限任务流。 如果任务流的属性“ URL invoke”设置为“ url-invoke-allowed”&#xff0c;则启用此功能&#xff0c;该功能通常在集成项目中使用。 通常&#xff0c;客户端&#xff08;或调用者&#x…

(十二)Bind读取配置到C#实例

继续上一节的&#xff0c;接下来用Options或者Bind把json文件里的配置转成C#的实体&#xff0c;相互之间映射起来。首先新建一个asp.net core mvc项目OptionsBindSampleStartup.cs&#xff0c;这里用依赖注入把Configuration加进来 1 public IConfiguration Configurat…

转-测试用例-常用控件

1. 文本框 是否是必填项 是 为空时提交&#xff0c;给出提示 输入空格时提交&#xff0c;给出提示 否 为空时提交&#xff0c;可提交成功 不为空时提交&#xff0c;提交后内容与输入的一致&#xff0c;存储到数据库中正确 是否支持TAB键在文本框中输入回车键&#xff0c;是…

java 项目做多级缓存_【开源项目系列】如何基于 Spring Cache 实现多级缓存(同时整合本地缓存 Ehcache 和分布式缓存 Redis)...

一、缓存当系统的并发量上来了&#xff0c;如果我们频繁地去访问数据库&#xff0c;那么会使数据库的压力不断增大&#xff0c;在高峰时甚至可以出现数据库崩溃的现象。所以一般我们会使用缓存来解决这个数据库并发访问问题&#xff0c;用户访问进来&#xff0c;会先从缓存里查…

[译] SpaceAce 了解一下,一个新的前端状态管理库

原文地址&#xff1a;Introducing SpaceAce, a new kind of front-end state library原文作者&#xff1a;Jon Abrams译文出自&#xff1a;掘金翻译计划本文永久链接&#xff1a;https://github.com/xitu/gold-miner/blob/master/TODO1/introducing-spaceace-a-new-kind-of-fro…

Spring MVC:带有CNVR卷的REST应用程序。 3

这是带有CNVR的Spring MVC REST教程的最后一部分。 在这里&#xff0c;我将演示所有这些东西如何工作&#xff0c;这是我在前两部分中开发的。 对于每种类型的CRUD操作&#xff0c;这将分为四个部分&#xff1a;CREATE&#xff0c;READ&#xff0c;UPDATE&#xff0c;DELETE。 …

Python学习笔记——txt文件转csv文件

import numpy as np import pandas as pdtxt np.loadtxt(data1.txt) txtDF pd.DataFrame(txt) txtDF.to_csv(file1.csv, indexFalse)转载于:https://www.cnblogs.com/yucen/p/9343574.html

左侧固定,右侧自适应的布局方式(新增评论区大佬教的方法)

一.浮动布局 1.先让固定宽度的div浮动&#xff01;使其脱离文档流。 2.margin-left的值等于固定div的宽度相等。 .aside{float: left;width: 200px;background-color: red;}.content{margin-left: 200px;background-color: blue;}<div class"aside">Lorem ipsu…

java 中io的删除文件_总结删除文件或文件夹的7种方法-JAVA IO基础总结第4篇

本文是Java IO总结系列篇的第4篇&#xff0c;前篇的访问地址如下&#xff1a;如果您阅读完成&#xff0c;觉得此文对您有帮助&#xff0c;请给我点个赞&#xff0c;您的支持是我不竭的创作动力。为了方便大家理解&#xff0c;我特意制作了本文对应的视频&#xff1a;总结删除文…