【luogu P2385 青铜莲花池】 题解
题目链接:https://www.luogu.org/problemnew/show/P2385
莲花池什么的最漂亮啦!
最近刷了两天搜索= =我搜索一直是弱菜
直接套bfs
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, m, m1, m2, sx, sy, ex, ey;
struct point{
int x, y, t;
}q[];
int ma[][];
int fx[];
int fy[];
void bfs()
{
int tail = ,head = ;
q[head].x = sx, q[head].y = sy, q[head].t = ;
while(head!=tail)
{
for(int i = ; i <= ; 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+);
return ;
}
if(nowx > m || nowx <= || nowy > n || nowy <= || ma[nowx][nowy] == ) continue;
ma[nowx][nowy] = ;
q[tail].x = nowx;
q[tail].y = nowy;
q[tail].t = q[head].t + ;
tail++;
}
head++;
} }
int main()
{
memset(ma,,sizeof(ma));
scanf("%d%d%d%d",&m,&n,&m1,&m2);
for(int i = ; i <= m; i++)
for(int j = ; j <= n; j++)
{
scanf("%d",&ma[i][j]);
if(ma[i][j]==)
{
sx = i;
sy = j;
}
if(ma[i][j]==)
{
ex = i;
ey = j;
}
if(ma[i][j] == )
{
ma[i][j] = ;
}
}
fx[] = m1, fx[] = m1, fx[] = -m1, fx[] = -m1, fx[] = m2, fx[] = m2, fx[] = -m2, fx[] = -m2;
fy[] = m2, fy[] = -m2, fy[] = m2, fy[] = -m2, fy[] = m1, fy[] = -m1, fy[] = m1, fy[] = -m1;
bfs();
return ;
}
【luogu P2385 青铜莲花池】 题解的更多相关文章
- AOJ.865 青铜莲花池 (BFS)
AOJ.865 青铜莲花池 (BFS) 题意分析 典型的BFS 没的说 代码总览 #include <iostream> #include <cstdio> #include ...
- luogu P1126 机器人搬重物 题解
luogu P1126 机器人搬重物 题解 题目描述 机器人移动学会(\(RMI\))现在正尝试用机器人搬运物品.机器人的形状是一个直径\(1.6\)米的球.在试验阶段,机器人被用于在一个储藏室中搬运 ...
- 【luogu P2491 [SDOI2011]消防】 题解
题目链接:https://www.luogu.org/problemnew/show/P2491 题外话: OI一共只有三种题--会的题,不会的题,二分题. 题解: step 1 求树的直径,把树的直 ...
- 【luogu P1040 加分二叉树】 题解
题目链接:https://www.luogu.org/problemnew/show/P1040 今天考试考了一个区间DP...没错就是这个... 太蒟了真是连区间DP都不会...看了看题解也看不懂, ...
- Luogu P1351 联合权值 题解
这是一个不错的树形结构的题,由于本蒟蒻不会推什么神奇的公式其实是懒得推...,所以很愉快的发现其实只需要两个点之间的关系为祖父和儿子.或者是兄弟即可. 然后问题就变得很简单了,只需要做一个正常的DFS ...
- 【luogu P1850 换教室】 题解
题目链接:https://www.luogu.org/problemnew/show/P1850 难的不在状态上,难在转移方程. (话说方程写错居然还有84分= =) #include <cst ...
- 【luogu P1558 色板游戏】 题解
题目链接:https://www.luogu.org/problemnew/show/P1558 我知道三十棵线段树很暴力,可是我们可以状压啊. 颜色最多30,不会爆int 另外 吐槽评测机 #inc ...
- 【luogu P3953 逛公园】 题解
题目链接:https://www.luogu.org/problemnew/show/P3953 题外话:感觉2017年神题好多..这还不是最神的一道,真在考场上我也就写个最短路计数暴力了.现在在大佬 ...
- 【luogu P1608 路径统计】 题解
题目链接:https://www.luogu.org/problemnew/show/P1608 补上一发最短路计数! 感谢王强qwqqqq @Lance1ot #include <queue& ...
随机推荐
- [转]sudo: sorry, you must have a tty to run sudo问题
使用不同账户,执行执行脚本时候sudo经常会碰到 sudo: sorry, you must have a tty to run sudo这个情况,其实修改一下sudo的配置就好了vi /etc/su ...
- Go语言下载网络图片或文件
最近闲来无事, 于是就简单学习了下Go语言的基本的用法.由于实践才是最快的学习方法,所以这里就以下载网络图片或文件入手来学习Go语言 文件下载到本地,通常的思路就是先获得网络文件的 输入流 以及本地文 ...
- Git使用教程,感觉比较全,所以【转载】
一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...
- ul+js模拟select+改进
html: <div class="select_box"> <input type="text" value="还款方式" ...
- spring+springmvc+hibernate整合遇到的问题
spring+springmvc+hibernate整合遇到的问题2016年10月20日 23:24:03 守望dfdfdf 阅读数:702 标签: ssh学习经历的异常exception异常框架更多 ...
- 2、Spring之AOP
AOP术语 通知:定义了切面是什么以及何时使用.除了要描述页面要完成的工作,通知还解决了何时执行这个工作的问题. 连接点:连接点是一个物理的存在.这个点可以是调用方法时.抛出异常时.甚至是修改一个字段 ...
- FTP FileZilla Server 本地加密C# 实现
最近公司要做一个资料管理模块,因系统是C/S架构,原来小文件都是直接使用7Z压缩后保存到SQL Server数据库 而资料管理模块也就是文件上传,下载加权限管理,考虑文件较多,还可能比较大,所以打算在 ...
- Form表单元素
Form表单元素 action method input: name value type: text password button radio checkbox file submit reset ...
- Vue中使用eslint
.eslintrc.js module.exports = { root: true, parser: 'babel-eslint', "env": { "browser ...
- JavaScript简易动画
<p id="s">fly</p> <script> function move(){ var id=document.getElementBy ...