洛谷 P1825 【[USACO11OPEN]玉米田迷宫Corn Maze】
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;
}
洛谷 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 ...
- 【luogu P1825 [USACO11OPEN]玉米田迷宫Corn Maze】 题解
题目链接:https://www.luogu.org/problemnew/show/P1825 带有传送门的迷宫问题 #include <cstdio> #include <cst ...
- [USACO11OPEN]玉米田迷宫Corn Maze
题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...
- 洛谷P1879 [USACO06NOV]玉米田Corn Fields(状压dp)
洛谷P1879 [USACO06NOV]玉米田Corn Fields \(f[i][j]\) 表示前 \(i\) 行且第 \(i\) 行状态为 \(j\) 的方案总数.\(j\) 的大小为 \(0 \ ...
- 【洛谷P1879】玉米田Corn Fields
玉米田Corn Fields 题目链接 此题和互不侵犯状压DP的做法类似 f[i][j]表示前i行,第i行种植(1)/不种植(0)构成的二进制数为j时的方案数 首先我们可以预处理出所有一行中没有两个相 ...
- C++ 洛谷 P1879 [USACO06NOV]玉米田Corn Fields
没学状压DP的看一下 合法布阵问题 P1879 [USACO06NOV]玉米田Corn Fields 题意:给出一个n行m列的草地(n,m<=12),1表示肥沃,0表示贫瘠,现在要把一些牛放在 ...
随机推荐
- python操作jenkins、python-jenkins api
Jenkins作为最流行的自动化流程的核心工具,我们使用它自带的web-ui完全可以满足日常的构建及发布工作,但是如果需要和其他系统做集成就必须二次开发或者通过API方式进行交互了. Jenkins介 ...
- 第一个Golang程序
1. 第一个 HelloGolang 程序 1.1 Go 源程序的基本概念 Go 源程序就是一个特殊格式的文本文件,可以使用任意文本编辑软件做 Go 的开发 Go 程序的 文件扩展名 通常都是 .go ...
- Java自学-接口与继承 内部类
Java 内部类 内部类分为四种: 非静态内部类 静态内部类 匿名类 本地类 步骤 1 : 非静态内部类 非静态内部类 BattleScore "战斗成绩" 非静态内部类可以直接在 ...
- python爬虫---详解爬虫分类,HTTP和HTTPS的区别,证书加密,反爬机制和反反爬策略,requests模块的使用,常见的问题
python爬虫---详解爬虫分类,HTTP和HTTPS的区别,证书加密,反爬机制和反反爬策略,requests模块的使用,常见的问题 一丶爬虫概述 通过编写程序'模拟浏览器'上网,然后通 ...
- 使用JDBC,完成数据库批量添加数据操作:
第一步:定义一个key String key = "into 表名(字段1,字段2,字段3)"; 第二步:定义一个可以增长的变量 StringBuffer values = new ...
- React学习笔记①
三种导出方式 export let num = 1://1 let num2 = 2://2 export {num2};//2 export default {default}//3 三种导入方式 ...
- python 使用Anaconda管理项目环境
Pycharm没有内置的python解释器,需要我们自己下载python解释器. 在很多python项目中,会导入第三方的模块,逐个去下载导入很不方便. 我们通常使用Anaconda来管理python ...
- springboot:使用JPA-Hibernate
步骤: 在pom.xml文件中添加mysql,spring-data-jpa的依赖. <!-- 添加mysql数据库驱动依赖--> <dependency> <group ...
- ML-对偶(Duality)问题初识
Primal vs Dual 为什么要把原始问题(primal) 转为 对偶问题(dual), 主要原因在于, 求解方便吧大概. 对偶问题 原始问题和其对偶问题, 都是对看待同一个问题的,从不同角度, ...
- FFMPEG 命令行工具-ffprobe
ffprobe 简介 ffprobe 是一个多媒体流分析工具.它从多媒体流中收集信息,并且以人类和机器可读的形式打印出来. 它可以用来检测多媒体流的容器类型,以及每一个多媒体流的格式和类型.它可以作为 ...