P1825 [USACO11OPEN]Corn Maze S

Corn Maze S(玉米田迷宫)

This past fall, Farmer John took the cows to visit a corn maze. But this wasn’t just any corn maze: it featured several gravity-powered teleporter slides, which cause cows to teleport instantly from one point in the maze to another. The slides work in both directions: a cow can slide from the slide’s start to the end instantly, or from the end to the start. If a cow steps on a space that hosts either end of a slide, she must use the slide.
The outside of the corn maze is entirely corn except for a single exit.
The maze can be represented by an N x M (2 <= N <= 300; 2 <= M <= 300) grid. Each grid element contains one of these items:

  • Corn (corn grid elements are impassable)
  • Grass (easy to pass through!)
  • A slide endpoint (which will transport a cow to the other endpoint)
  • The exit

A cow can only move from one space to the next if they are adjacent and neither contains corn. Each grassy space has four potential neighbors to which a cow can travel. It takes 1 unit of time to move from a grassy space to an adjacent space; it takes 0 units of time to move from one slide endpoint to the other.

Corn-filled spaces are denoted with an octothorpe (#). Grassy spaces are denoted with a period (.). Pairs of slide endpoints are denoted with the same uppercase letter (A-Z), and no two different slides have endpoints denoted with the same letter. The exit is denoted with the equals sign (=).

Bessie got lost. She knows where she is on the grid, and marked her current grassy space with the ‘at’ symbol (@). What is the minimum time she needs to move to the exit space?

考验你们英语能力的时候到了:) (bushi)

题目大意:

给你一个n * m的char地图,@是起点;=是终点;.是普通的能走的草地;#是不能走的障碍物;会有一些传送门,用"A~Z"表示,表示方式:传送门可能会有多对,每一对所表示的字母都是相同的,使用传送门的一端到另一端之间的这段距离不耗步数。
问:从起点到终点的最小步数为多少?

思路:

这道题是一道BFS的典型应用,抛开传送门这个东西,就是一道BFS裸题,(不愧是你,USACO),既然是搜索题,那就上代码吧!!!

前排提示:建议有一定的BFS基础的朋友来看这道题解,会获得更好的观看体验。

代码:

#include<iostream>
#include<cstdio>
#include<queue>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
struct node			//定义结构体:坐标与步数
{
   
	int x;
	int y;
	int ans;
}t;
char a[310][310];	//地图
bool b[310][310<
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值