Cpp环境【POJ2435】【CQYZOJ3034】【USACO2005 U S Open Silver】Navigating the City城市交通

该博客介绍了如何帮助奶牛在城市中驾驶出租车,提供从起点'S'到终点'E'的最短路线。文章通过一个具体的地图示例展示了路径规划,并提出了解决方案,即使用BFS/DFS算法计算每个节点到起点和终点的距离,然后找出最短路径上的节点并输出路径。
摘要由CSDN通过智能技术生成

Description 【问题描述】


  A dip in the milk market has forced the cows to move to the city. The only employment available is in the venerable field of taxi-driving. Help the cows learn their way around the city.
  Given a city map with E (1 <= E <= 40) east/west street locations and N (1 <= N <= 30) north/south street locations, create instructions for a taxi driver to navigate from the start of his route (marked ‘S’) to the end (marked ‘E’). Each instruction is a direction (one of ‘N’, ‘E’, ‘S’, or ‘W’) followed by a space followed by an integer that tells how many blocks to drive in that direction. If multiple routes are available, your program should output the shortest route. The shortest route is guaranteed to exist and be unique.
  The map is depicted as a grid of ‘+’s that represent intersections and a set of roads depicted as ‘-’ and ‘|’. Buildings and other obstacles are shown as ‘.’s. Here is a typical map:
  
+-+-+.+-+-+
|…|…..|
+-+.+-+-+-+
..|…….|
S-+-+-+.E-+

  The taxi should go east, north, west, north, east two blocks, and so on. See the output format and sample solution below for its complete route.


  由于奶牛市场的需求,奶牛必须前往城市,但是唯一可用的交通工具是出租车。教会奶牛如何在城市打的。

  给出一个城市的地图,东西街区E条,南北街区N条。制作一个开车指南给出租车司机,告诉他如何从起点(用S表示)到终点(用E表示)。每一个条目用空格分开成两部分,第一个部分是方向(N,E,S,W之一),第二个是一个整数,表示要沿着这个方向开几个十字路口。如果存在多条路线,你应该给出最短的。数据保证,最短的路径存在且唯一。

  地图中’+’表示十字路口,道路用’|’和’-‘表示。建筑物和其他设施用’.’表示,下面是一张地图:
    +-+-+.+-+-+
    |…|…..|
    +-+.+-+-+-+
    ..|…….|
    S-+-+-+.E-+
    
  出租车可以沿着东、北、西、北,东开两个十字路口,依次类推,具体将有样例给出。(输入数据保证路径唯一)   

Input 【输入格式】

  • Line 1: Two space-separated integers, N and E.
  • Lines 2..2*N: These lines each contain 2*E-1 characters and encode the map of the street. Every other input line gives the data for the east/west streets; the remaining lines show the north/south streets. The format should be clear from the example.

第1行:两个用空格各开的整数N和E。
第2到第2N行:每行有2E-1个字符,表示地图。

Output 【输出格式】

  • Lines 1..?: Each line contains a direction letter and a number of blocks to travel in that direction.

  每行有一个表示方向的字母和一个表示要开几个十字路口的数字表示。

Sample Input 【输入样例】

3 6
+-+-+.+-+-+
|…|…..|
+-+.+-+-+-+
..|…….|
S-+-+-+.E-+

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值