【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时的方案数 状 ...
随机推荐
- MySql中存储引擎MyISAM与InnoDB区别于选择
InnoDB: 支持事务处理等 不加锁读取 支持外键 支持行锁 不支持FULLTEXT类型的索引 不保存表的具体行数,扫描表来计算有多少行 DELETE 表时,是一行一行的删除 InnoDB 把数据和 ...
- js数组的splice函数
一直没搞懂数组的splice函数,今天稍微测试了一下,了解了它的功能,在这里记录一下 1.测试 测试① var a = [1,2,3]; console.info(a.splice(1,1)); co ...
- MySQL root 密码修改
小伙伴要在以前的服务器上装个代码版本控制的软件,要用到数据库,可是想来找去root密码还是忘了,其他已经安装的服务都是用的专用账户配置文件里要找不到root用户的密码.用以下方法将密码强制修改掉: 1 ...
- 深入理解jQuery插件开发总结(二)
1,开始 可以通过为jQuery.fn增加一个新的函数来编写jQuery插件.属性的名字就是你的插件的名字: jQuery.fn.myPlugin = function(){ //开始写你的代码吧! ...
- js截取关键字之后的字符串
需求:截取下面字符串"="之后的所有字符 var str = "12345=6"; //要截取的字符串 var index = str.indexOf(&quo ...
- 【阿里云产品公测】ACE下上传文件永久存储实践
本帖主要内容: ;$,=VB:' 在阿里云的ACE下,我是如何实现让上传的文件永久保存的? ,%"!8T 本文以PHP为例,具体知识点如下: WD# 96V 第一,扩展服务“存储 ...
- Linux 下载百度网盘大文件
Linux 下没有百度网盘客户端,用浏览器下载速度慢得急死人 鼠标移到链接处, 右键, 然后复制链接 接着在终端里输入 axel -n 50 -o filename.ext “粘贴链接到此处” axe ...
- 千里之堤毁于蚁穴(慎用HD Wallets)
转自:http://blog.sina.com.cn/s/blog_12ce70a430102vbu9.html 千里之堤毁于蚁穴(慎用HD Wallets) -- 随机系列谈之四 现在我们都该明白, ...
- Android之自定义View以及画一个时钟
https://www.2cto.com/kf/201509/443112.html 概述: 当Android自带的View满足不了开发者时,自定义View就发挥了很好的作用.建立一个自定义View, ...
- html 颜色在线取色器
推荐一个链接 还不错 http://www.atool.org/colorpicker.php