洛谷 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表示贫瘠,现在要把一些牛放在 ...
随机推荐
- framework7 下拉刷新、无限滚动
下拉刷新: html: <div class="page-content ptr-content"> <%--下拉刷新图标--%> <div clas ...
- Echarts 学习系列(1)-5分钟上手ECharts
目录 写在前面 下载Echarts和主题 绘制一个简单的图表 写在前面 最近,在做某个项目的时候.需要使用的可视化的图表显数据.最后,选择了百度的Echarts. 下载Echarts和主题 1.获取E ...
- ajax 执行成功以后返回的数据走的是error方法而不是success方法的问题
今天在一个功能的时候发现写的ajax的方法执行后台代码成功后返回前台时执行的是error方法而不是success方法,代码如下 jQuery('#form').ajaxSubmit({ type: & ...
- wps金山文档在线编辑--.Net 接入指南
一.申请成为服务商,对金山文档在线服务进行申请 ①进入官网 https://open.wps.cn/ ②申请后如下图,点击右下角的进入服务 ③申请成功后 ④数据回调URL一定是服务器地址,本次我使用的 ...
- 【WEB基础】HTML & CSS 基础入门(10)布局与定位
块级元素和行内元素 HTML里的元素可以分为块级元素和行内元素两大类:
- MongoDB常用数据库命令第一集
1.查询操作(1)Help查看命令提示helpdb.help()db.test.help()db.test.find().help()(2)创建/切换数据库use music(3)查询数据库show ...
- webpack 入门和常用插件的使用
常用配置参数 module.exports = { context: path.resolve(__dirname, '../'), entry: { app: './src/main.js' }, ...
- 全面了解Cookie
一.Cookie的出现 浏览器和服务器之间的通信少不了HTTP协议,但是因为HTTP协议是无状态的,所以服务器并不知道上一次浏览器做了什么样的操作,这样严重阻碍了交互式Web应用程序的实现. 针对上述 ...
- Java语言的介绍
1. 计算机语言 语言:沟通交流的方式 计算机语言:人与计算机之间的交流方式 java是一门计算机编程语言,也是意大利自行车品牌 软件工程师,java开发工程师 <--------------- ...
- Python的object和type理解及主要对象层次结构
一.Object与Type 1.摘自Python Documentation 3.5.2的解释 Objects are Python’s abstraction for data. All data ...