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<