P1825

传送门

简单的题意

就是一个有传送门的迷宫问题(我一开始以为是只有1个传送门,然后我就凉了).

大体思路

先把传送门先存起来,然后跑一下\(BFS\)。

然后,就做完了.

代码鸭

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#define A 305 using namespace std;
int ans, n, m, map[A][A], lu[400010][4];
int u[5] = {0, 0, 0, -1, 1}, v[5] = {0, -1, 1, 0, 0};
int dx, dy, sx, sy;
struct node {
int x, y;
bool s;
} w1[27], w2[27]; void bfs() {
int head = 0, tail = 1;
lu[tail][1] = sx, lu[tail][2] = sy, lu[tail][3] = 1;
map[sx][sy] = 1;
while(head < tail) {
head++;
for(int i = 1; i <= 4; i++) {
int x = lu[head][1] + u[i], y = lu[head][2] + v[i];
//if(w1.x == x && w1.y == y) x = w2.x, y = w2.y;
//if(w2.x == x && w2.y == y) x = w1.x, y = w1.y;
for(int i = 1; i <= 26; i++)
if(x == w1[i].x && y == w1[i].y) {
x = w2[i].x, y = w2[i].y;
break;
} else if(x == w2[i].x && y == w2[i].y) {
x = w1[i].x, y = w1[i].y;
break;
}
if(x >= 1 && x <= n && y >= 1 && y <= m && map[x][y] == 0) {
tail++;
map[x][y] = 1;
lu[tail][1] = x, lu[tail][2] = y, lu[tail][3] = lu[head][3] + 1;
if(x == dx && y == dy) {
ans = lu[tail][3];
head = tail;
break;
}
}
}
}
} int main() {
char s;
scanf("%d%d",&n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin>>s;
if (s == '=') dx = i, dy = j, map[i][j] = 0;
if (s == '@') sx = i, sy = j, map[i][j] = 0;
if (s == '#') map[i][j] = 1;
if (s == '.') map[i][j] = 0;
if (s >= 'A' && s <= 'Z') {
map[i][j] = 0;
if (w1[s - 'A' + 1].s == 0) w1[s - 'A' + 1].s = 1, w1[s - 'A' + 1].x = i, w1[s - 'A' + 1].y = j;
else w2[s - 'A' + 1].s = 1, w2[s - 'A' + 1].x = i, w2[s - 'A' + 1].y = j;
}
}
bfs();
cout<<ans - 1;
}

最新文章

  1. Thread Object wait() notify()基本
  2. Android Studio一些常用快捷键及快捷键冲突解决
  3. AngularJs项目文件以及文件夹结构
  4. mfc打开程序
  5. 连接到Windows Azure Point to Site VPN
  6. UEFI与MBR区别
  7. Android手机同步电脑端google chrome书签
  8. c# 模拟get和post
  9. CodeForces 682C Alyona and the Tree (树+dfs)
  10. mvc 路由 使用
  11. sql server 2008 在安装了活动目录以后无法启动服务了
  12. 【JSP】JSP与oracle数据库交互案例
  13. 3TB硬盘的容量已经超出了传统分区标准的支持
  14. ES 6 : 变量的解构赋值
  15. 【转】JDBC学习笔记(9)——DBUtils的使用
  16. Sqoop2安装记录
  17. 在socket的server端处理client端发来的数据
  18. ERROR org.hibernate.hql.internal.ast.ErrorCounter unexpected token: form 异常解决
  19. SkylineGlobe 6.5 如何实现简单多边形的动态绘制 C#示例代码
  20. Python小白学习之路(二十一)—【迭代器】

热门文章

  1. APUE之第5章——标准I/O库
  2. C#读写修改设置调整UVC摄像头画面-全景
  3. java 枚举示例
  4. python3 marshmallow学习
  5. 2019 开创java面试笔试题 (含面试题解析)
  6. maven项目整合SSM配置log4j, 实现控制台打印SQL语句
  7. 如何使用Python的Django框架创建自己的网站
  8. 一个tomcat同时部署多个项目
  9. ARM架构体系
  10. K-th Path CodeForces - 1196F