洛谷 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表示贫瘠,现在要把一些牛放在 ...
随机推荐
- spring接口文档注解:@ApiOperation
@ApiOperation不是spring自带的注解是swagger里的 com.wordnik.swagger.annotations.ApiOperation; @ApiOperation和@Ap ...
- mysql 5.7 修改root密码允许远程连接
1.修改root密码(其他用户类似) 试过网上看的一些 在mysql数据库执行 update user set password='新密码' where user='root' 执行说找不到字段, ...
- 检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配
解决方案: [DllImport("Dll.dll")]改为[DllImport("Dll.dll", CallingConvention=CallingCon ...
- gcc 编译过程
gcc 编译过程从 hello.c 到 hello(或 a.out)文件, 必须历经 hello.i. hello.s. hello.o,最后才得到 hello(或a.out)文件,分别对应着预处理. ...
- 2019 竞网智赢java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.竞网智赢等公司offer,岗位是Java后端开发,因为发展原因最终选择去了竞网智赢,入职一年时间了,也成为了面 ...
- 【转载】C#中ArrayList集合类和List集合类的比较
List集合类和ArrayList集合类都是C#语言中用于存储集合数据的集合类,两者都可灵活的插入.删除以及访问元素等等.但List集合和ArrayList集合的差别还是挺大的,首先List集合类是泛 ...
- DataPipeline数据融合重磅功能丨一对多实时分发、批量读取模式
为能更好地服务用户,DataPipeline最新版本支持: 1. 一个数据源数据同时分发(实时或定时)到多个目的地: 2. 提升Hive的使用场景: 写入Hive目的地时,支持选择任意目标表字段作为 ...
- 关于控制Broker端入站连接数的讨论
Kafka Broker端处理请求采用Reactor模型.每台Broker上有个类似于Dispatcher的Acceptor线程,还有若干个处理请求的Processor线程(当然真正处理请求逻辑的线程 ...
- 为什么Audition CC2017扫描不了电音插件,你需要这个工具
一时兴起,我也去下载并安装了Audition的音频后期处理软件,版本是cc2017.简单熟悉了对自己声音修理外,我还想添加一点电音的效果显得洋气一些.在网上下载并安装了warves tune后,发现A ...
- NGINX PHP 报错整理合集
NGINX PHP "No input file specified" 修改php.ini conf cgi.fix_pathinfo=1; 修改nginx.conf,中的fast ...