【luogu P1825 [USACO11OPEN]玉米田迷宫Corn Maze】 题解
题目链接:https://www.luogu.org/problemnew/show/P1825
带有传送门的迷宫问题
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 2001;
char map[maxn][maxn];
int fx[4] = {0, 1, 0, -1};
int fy[4] = {1, 0, -1, 0};
int n, m, ex, ey, sx, sy;
struct map{
int x, y, t;
}q[4000001];
struct door{
int x1, y1, x2, y2;
}d[40];
void bfs()
{
int head = 1, tail = 2;
q[head].x = sx, q[head].y = sy, q[head].t = 0;
while(head != tail)
{
for(int i = 0; i < 4; i++)
{
int nowx = q[head].x + fx[i];
int nowy = q[head].y + fy[i];
if(nowx == ex && nowy == ey)
{
printf("%d", q[head].t + 1);
return ;
}
if(nowx > n || nowx <= 0 || nowy > m || nowy <= 0 || map[nowx][nowy] == '#') continue;
if(map[nowx][nowy] >= 'A' && map[nowx][nowy] <= 'Z')
{
if(nowx == d[map[nowx][nowy]-'A'].x1 && nowy == d[map[nowx][nowy]-'A'].y1)
{
q[tail].x = d[map[nowx][nowy]-'A'].x2;
q[tail].y = d[map[nowx][nowy]-'A'].y2;
q[tail].t = q[head].t + 1;
tail++;
}
if(nowx == d[map[nowx][nowy]-'A'].x2 && nowy == d[map[nowx][nowy]-'A'].y2)
{
q[tail].x = d[map[nowx][nowy]-'A'].x1;
q[tail].y = d[map[nowx][nowy]-'A'].y1;
q[tail].t = q[head].t + 1;
tail++;
}
}
else
{
map[nowx][nowy] = '#';
q[tail].x = nowx;
q[tail].y = nowy;
q[tail].t = q[head].t + 1;
tail++;
}
}
head++;
}
}
int main()
{
cin>>n>>m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
cin>>map[i][j];
if(map[i][j] == '@') sx = i, sy = j;
if(map[i][j] == '=') ex = i, ey = j;
if(map[i][j] <= 'Z' && map[i][j] >= 'A')
{
if(d[map[i][j]-'A'].x1 == 0 && d[map[i][j]-'A'].y1 == 0)
{d[map[i][j]-'A'].x1 = i, d[map[i][j]-'A'].y1 = j; continue;}
if(d[map[i][j]-'A'].x2 == 0 && d[map[i][j]-'A'].y2 == 0)
{d[map[i][j]-'A'].x2 = i, d[map[i][j]-'A'].y2 = j; continue;}
}
}
bfs();
return 0;
}
【luogu P1825 [USACO11OPEN]玉米田迷宫Corn Maze】 题解的更多相关文章
- 洛谷——P1825 [USACO11OPEN]玉米田迷宫Corn Maze
P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题目描述 This past fall, Farmer John took the cows to visit a corn maz ...
- 洛谷 P1825 [USACO11OPEN]玉米田迷宫Corn Maze
P1825 [USACO11OPEN]玉米田迷宫Corn Maze 题目描述 This past fall, Farmer John took the cows to visit a corn maz ...
- 洛谷—— P1825 [USACO11OPEN]玉米田迷宫Corn Maze
https://www.luogu.org/problem/show?pid=1825 题目描述 This past fall, Farmer John took the cows to visit ...
- P1825 [USACO11OPEN]玉米田迷宫Corn Maze
题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...
- [USACO11OPEN]玉米田迷宫Corn Maze
题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...
- 洛谷 P1825 【[USACO11OPEN]玉米田迷宫Corn Maze】
P1825 传送门 简单的题意 就是一个有传送门的迷宫问题(我一开始以为是只有1个传送门,然后我就凉了). 大体思路 先把传送门先存起来,然后跑一下\(BFS\). 然后,就做完了. 代码鸭 #inc ...
- 【luogu P1879 [USACO06NOV]玉米田Corn Fields】 题解
题目链接:https://www.luogu.org/problemnew/show/P1879 状压DP. 设dp[i][j]表示第i行,状态为j的方案数 初始dp[0][0] = 1 这样一共12 ...
- luogu P1879 [USACO06NOV]玉米田Corn Fields
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- 【Luogu】P1879玉米田(状压DP)
题目链接 数据范围这么小,难度又这么大,一般就是状态压缩DP了. 对输入进行处理,二进制表示每一行的草地状况.如111表示这一行草地肥沃,压缩成7. 所以f[i][j]表示第i行状态为j时的方案数 状 ...
随机推荐
- Java 基础(2)——编译运行 & 规范
上节学到 Java 的编译与运行,我们已经学会了怎么去执行一个写好(假装我们已经会写了)的代码,这篇当然要试试手啦 O(∩_∩)O 哈哈~ 小试一下 新建一个 HelloAhanWhite.java ...
- java爬虫之入门基础
相比于C#,java爬虫,python爬虫更为方便简要,首先呢,python的urllib2包提供了较为完整的访问网页文档的API,再者呢对于摘下来的文章,python的beautifulsoap提供 ...
- influxdb 端口、数据结构、写数据
InfluxDB 是一个开源,分布式,时间序列,事件,可度量和无外部依赖的数据库. InfluxDB有三大特性: Time Series (时间序列):你可以使用与时间有关的相关函数(如最大,最小,求 ...
- Eclipse自定义启动画面和状态栏图标以及各种小图标的含义
一. 启动画面自定义 第一种情况:纯Eclipse 找到Eclipse安装路径下\eclipse\plugins\org.eclipse.platform_3.7.2.v201202080800,具体 ...
- flask-login的简单实用
# encoding: utf-8 from flask import Flask, Blueprint from flask_login import (LoginManager, login_re ...
- DOM Tree
DOM Tree 什么是DOM树:网页的所有内容在内存当中,其实是以树形结构存储的 何时创建:当浏览器,读取html中内容的时候,会马上开始创建DOM树. 如何创建: 1.读到HTML的时候还没有 ...
- easyui numberbox输入框 编辑不可编辑的切换
背景:申请单里需要选费用类型,费用类型有的有子明细项,有个合计项 当有子明细项的时候,合计项的值是通过弹出的子明细项价格的总和(设置为可编辑没问题,因为点击出来弹框,编辑不了) 没有子明细 ...
- TcpListener、TcpClient
1.TcpClient using System; using System.Text; using System.Net.Sockets; namespace tcpclient { class t ...
- February 9 2017 Week 6 Thursday
Happy life lies in a peaceful mind. 幸福的生活存在于心绪的宁静当中. What can be seen as happy life? Maybe the answe ...
- ZT sigprocmask,sigpending函数
sigprocmask,sigpending函数 分类: LINUX 2012-02-02 16:39 905人阅读 评论(0) 收藏 举报 signalredhatnulllinux [sigpro ...