题目链接: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. Navicat Premium v12.0.23.0 破解教程x86,x64通用,手动破解

    教程来源于:吾爱破解网站 ----------更新线----------- 2018.01.23 Navicat Premium v12.0.23.0 测试破解依然有效 ----------更新线-- ...

  2. ionic 打包安卓包 (debug调试版和 release发布版)

    一.配置环境: 先按照之前的文章,配置好环境需要: 安装jdk,配置环境变量:( http://www.cnblogs.com/loveyaxin/p/7520618.html) 安装android- ...

  3. BNU4299——God Save the i-th Queen——————【皇后攻击,找到对应关系压缩空间】

    God Save the i-th Queen Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      ...

  4. 从Linux服务器下载文件到本地

    通过安装xshell,连接服务器,通过以下命令可以方便的将服务器的文件下载到本地 #下载一个文件 sz filename #下载多个文件 sz filename1 filename2 #下载dir目录 ...

  5. C# 实现OrderBy按多个字段排序

    //倒序 list.OrderByDescending(i => i.a).ThenByDescending(i => i.b); //顺序 list.OrderBy(i => i. ...

  6. Java基础入门 - 简介

    官网:https://www.oracle.com Java分为三个体系: JavaEE: Java Platform, Enterprise Edition, Java平台企业版 JavaSE: J ...

  7. PHP环境配置解释

    PHP中注释:#,//,/* */ 一.修改Apache配置 DocumentRoot  "G:\PHP"        //修改完需要重启Apache //以下二选一 ----- ...

  8. 检测IE浏览器兼容Edge模式及IE11

    document.documentMode || +(navigator.userAgent.match(/MSIE (\d+)/) && RegExp.$1) 判断布尔值

  9. ref关键字的用法

    ref 关键字通过引用(而非值)传递参数. 通过引用传递的效果是,对所调用方法中的参数进行的任何更改都反映在调用方法中. 例如,如果调用方传递本地变量表达式或数组元素访问表达式,所调用方法会将对象替换 ...

  10. Java设计模式—策略模式

    1.策略模式(Strategy Pattern)是一种比较简单的模式,也叫做政策模式(PolicyPattern). 定义如下:     Define a family of algorithms,e ...