题目链接: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 青铜莲花池】 题解的更多相关文章

  1. AOJ.865 青铜莲花池 (BFS)

    AOJ.865 青铜莲花池 (BFS) 题意分析 典型的BFS 没的说 代码总览 #include <iostream> #include <cstdio> #include ...

  2. luogu P1126 机器人搬重物 题解

    luogu P1126 机器人搬重物 题解 题目描述 机器人移动学会(\(RMI\))现在正尝试用机器人搬运物品.机器人的形状是一个直径\(1.6\)米的球.在试验阶段,机器人被用于在一个储藏室中搬运 ...

  3. 【luogu P2491 [SDOI2011]消防】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2491 题外话: OI一共只有三种题--会的题,不会的题,二分题. 题解: step 1 求树的直径,把树的直 ...

  4. 【luogu P1040 加分二叉树】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1040 今天考试考了一个区间DP...没错就是这个... 太蒟了真是连区间DP都不会...看了看题解也看不懂, ...

  5. Luogu P1351 联合权值 题解

    这是一个不错的树形结构的题,由于本蒟蒻不会推什么神奇的公式其实是懒得推...,所以很愉快的发现其实只需要两个点之间的关系为祖父和儿子.或者是兄弟即可. 然后问题就变得很简单了,只需要做一个正常的DFS ...

  6. 【luogu P1850 换教室】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1850 难的不在状态上,难在转移方程. (话说方程写错居然还有84分= =) #include <cst ...

  7. 【luogu P1558 色板游戏】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1558 我知道三十棵线段树很暴力,可是我们可以状压啊. 颜色最多30,不会爆int 另外 吐槽评测机 #inc ...

  8. 【luogu P3953 逛公园】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3953 题外话:感觉2017年神题好多..这还不是最神的一道,真在考场上我也就写个最短路计数暴力了.现在在大佬 ...

  9. 【luogu P1608 路径统计】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1608 补上一发最短路计数! 感谢王强qwqqqq @Lance1ot #include <queue& ...

随机推荐

  1. UI特效资料-----ShaderWeaver

    主页:www.shaderweaver.com教程:www.shaderweaver.com/tutorials.html 1.一款插件,挺强大的 ShaderWeaver使用教程-基本操作介绍 ht ...

  2. IDEA 14.0 (默认模式) 快捷键

    IDEA 14.0 (默认模式) 快捷键 1.Alt+Shift+R:重命名变量名.类名.方法名(使用已经使用过的) 2.Ctrl+O :重写方法 3.Alt+Shift+P :实现接口 4.Alt+ ...

  3. MsysGit下GUI乱码问题解决

    在Windows下安装Git-preview-1.7.4后,使用中发现许多的乱码问题,感觉甚是不便.这是因为Git是在linux下开发的管理软件,而linux的编码方式是基于UTF-8的,所以移植到W ...

  4. FZU 2213——Common Tangents——————【两个圆的切线个数】

    Problem 2213 Common Tangents Accept: 7    Submit: 8Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  5. redis的有序集合(Sorted Sets)数据类型

    和Sets相比,Sorted Sets增加了一个权重参数score,使得集合中的元素能够按score进行有序排列,比如一个存储全班同学成绩的Sorted Sets,其集合value可以是同学的学号,而 ...

  6. Protocol Buffers教程

    今天想比较下pb和fastjson两个序列化后的大小.再看了一下pb序列化 pb官网:https://developers.google.com/protocol-buffers/ pb是啥 What ...

  7. 洛谷P2312 解方程(暴力)

    题意 题目链接 Sol 出这种题会被婊死的吧... 首先不难想到暴力判断,然后发现连读入都是个问题. 对于\(a[i]\)取模之后再判断就行了.注意判断可能会出现误差,可以多找几个模数 #includ ...

  8. iOS Touch ID 简易开发教程

    转自:NsstringFromName 支持系统和机型 iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统为iOS 8,虽然安装iOS 7系统的5s机型可以使用系统提供的指纹解锁 ...

  9. Strom入门

    Worker.Executor.Task详解: Storm在集群上运行一个Topology时,主要通过以下3个实体来完成Topology的执行工作:1. Worker Process(工作进程)——S ...

  10. js判断一个dom中是否包含另一个dom的方法

    首先,比较原始(蠢)的方法 function isChildOf(child, parent) { if(child && parent) { let parentNode = chi ...