题目链接: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. c#高级写法

    Linq的参考资料:https://www.cnblogs.com/liqingwen/p/5801249.html 1.判断str字符串中的逗号个数 string str = "1,2,3 ...

  2. Hash索引和B+树索引总结

    先说Hash索引 在理想的情况下,key非常分散,不存在Hash碰撞的话,采用Hash索引可以唯一得确定一个key的位置,并且这个位置上就只有一个key,所以查找时间复杂度是O(1),非常快,这是Ha ...

  3. 解决VMWARE 虚拟机安装64位系统“此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态

    VMWARE WORKSTATION 在安装64为操作系统报错,报错内容如图: 错误提示已经很清楚了,需要在BIOS 中打开intel VT-x g功能,开启此功能的前提是: 1.首先要确定的就是你的 ...

  4. 使用awstat分析Nginx的访问日志

    在我的上一篇文章<使用 Nginx 提升网站访问速度>中介绍了 Nginx 这个 HTTP 服务器以及如何通过它来加速网站的访问速度.在实际的网站运营中,我们经常需要了解到网站的访问情况, ...

  5. 查询指定tomcat应用的进程数

    假设应用名称为pear,查询指定tomcat应用pear的进程数: ps -ef |grep "/datong/tomcat-pear/" |grep -v tail | grep ...

  6. js实现CkeckBox全选与反选

    全选与反选 function SelectAll(){ var check = document.getElementsByTagName("input"); // 获取所有inp ...

  7. sql 行列转换

    create table #test1(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int) insert into #test1 valu ...

  8. asp.net的几种页面传值方式

    1."~/x/xx.aspx?id=" + id string id=Request.Params["id"].ToString(); 2.Response.R ...

  9. MVC5 model常见的写法

    1.数据库表中为ID的字段 [Key] //关键字 [Required] //不为空 [Display(Name = "ID")] public int id { get; set ...

  10. js之方法

    原文 在一个对象中绑定函数,称为这个对象的方法. 在JavaScript中,对象的定义是这样的: var xiaoming = { name: '小明', birth: 1990 }; 但是,如果我们 ...