一道宽搜模版题,可写错了两个地方的我只得了56(掩面痛哭)

http://10.37.2.111/problem.php?id=1345

先看看正确的

#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(int i = l; i<=r; i++)
using namespace std;

int read
{
    ; char ch = getchar();
     || ch > )  ch = getchar();
     && ch <= ) {x =  * x + ch - ; ch = getchar();}
    return x;
}

;

int n,m,k;
int sx,sy,ex,ey;
int ans = INT_MAX;
,,-, ,};//上,下,左,右;
,, ,-,};
struct node{int x,y,step;}st;
int th[N][N],vis[N][N];
int nx,ny;

void updata(int i,int p)
{
    ) (nx += p) > n ?nx = n : nx;     //上
    ) (nx -= p) <  ?nx =  : nx;//下
    ) (ny -= p) <  ?ny =  : ny;//左
    ) (ny += p) > m ?ny = m : ny;//右
}

void bfs()
{
    queue<node>q;
    st.step = ;
    st.x = sx;
    st.y = sy;
    q.push(st);
    vis[sx][sy]=;
    while(!q.empty())
    {
        node cur = q.front(); q.pop();
        );}
        up(i,,)
        {
            nx = cur.x + dx[i];
            ny = cur.y + dy[i];
|| ny <  || nx > n || ny > m || vis[nx][ny]) continue;
            vis[nx][ny] = ;
            node nxt; nxt.x = nx; nxt.y = ny; nxt.step = cur.step + ;
            q.push(nxt);
        }
    }
    printf("Impossible");
}

int main()
{
    freopen("hero2.in","r",stdin);
    n = read; m = read; k = read;
    int x,y;
    ;
    up(i,,k)
    {
        x = read; y = read; th[x][y] = read;
    }
    sx = read; sy = read;
    ex = read; ey = read;
    bfs();
}

错误1:代码笔误;

void updata(int i,int p)
{
    ) (nx += p) > n ?n : nx;     //上
    ) (nx -= p) <  ? : nx;//下
    ) (ny -= p) <  ? : ny;//左
    ) (ny += p) > m ?m : ny;//右
}

看出什么了吗? -> 忘了赋值了;

错误2:思维漏洞;

if(th[nx][ny]) updata(i,th[nx][ny]);

弹簧可以连续跳啊连续跳 -> 所以要多次更新

记住教训啊;

MZOJ 1345 hero的更多相关文章

  1. H5游戏开发之Stick Hero

    自从上次发布一个小恐龙游戏以后,到现在10天了,前后又写了3个游戏,挑了一个感觉比较有挑战的游戏和大家分享一下. 效果演示 这是我模拟一个苹果游戏<stick hero>游戏写的一个小游戏 ...

  2. BZOJ 1191 超级英雄 Hero 题解

    BZOJ 1191 超级英雄 Hero 题解 Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金 ...

  3. 2016HUAS暑假集训训练2 K - Hero

    题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...

  4. 【入门】匈牙利算法+HNOI2006 hero超级英雄

    一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里( ...

  5. 2016HUAS_ACM暑假集训2K - Hero(英雄)

    这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...

  6. bzoj 1191: [HNOI2006]超级英雄Hero

    1191: [HNOI2006]超级英雄Hero Time Limit: 10 Sec  Memory Limit: 162 MB 二分图匹配... Description 现在电视台有一种节目叫做超 ...

  7. HDU 4901 The Romantic Hero

    The Romantic Hero Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u D ...

  8. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  9. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

随机推荐

  1. as3.0影片简介失效,不阻碍下面影片简介的事件

    mast.mouseEnabled=false; mast.mouseChildren=false;

  2. as2.0 清除主时间轴上所有的影片简介

    for (var i in _root) { if (typeof _root[i] == "movieclip") { _root[i].swapDepths(1); _root ...

  3. JTAG-测试数据寄存器

    1.问题:JTAG中的数据寄存器的结构 JTAG标准规定了两个必须的数据寄存器: 1.旁通寄存器 2.边界扫描寄存器(已经在可测性设计-扫描通路中介绍了) 可选的的寄存器有: 1.器件标示寄存器(32 ...

  4. numpy学习之矩阵之旅

    一:特殊的矩阵 1.全0全1的矩阵 2.单位矩阵 单位矩阵:整个矩阵是n*n的,并且斜对角全是1 矩阵的加减法 1.矩阵相加,相减必须要有相同的行和列 二:数组的乘法(点成) 数组的乘法 list_1 ...

  5. python——线程相关

    使用python的threading中的Thread 下面是两种基本的实现线程的方式: 第一种方式———— #coding=utf-8 """ thread的第一种声明及 ...

  6. [Java学习]面向对象-抽象类;接口

    抽象类 语法 public abstract class A{ } 定义 抽象类无法实例化.但抽象类有构造方法,在子类创建对象时用. 抽象类中可以定义抽象方法public abstract void ...

  7. composer 安装新包失败的原因之一

    各种方法都尝试过了,然而最大的可能就是不能访问国外的资源! 1.使用vpnFQ下载 2.修改一下composer的配置,命令如下: composer config -g repo.packagist ...

  8. openshift上传java web项目

    下载当前客户端 OC(Openshift Client) https://mirror.openshift.com/pub/openshift-v3/clients/3.9.14/windows/oc ...

  9. js去除字符串空格(空白符)

    使用js去除字符串内所带有空格,有以下三种方法: ( 1 ) replace正则匹配方法 去除字符串内所有的空格:str = str.replace(/\s*/g,""); 去除字 ...

  10. Three.js粒子特效,shader渲染初探(一篇非常详细的介绍)

    Three.js粒子特效,shader渲染初探 转载来源:https://juejin.im/post/5b0ace63f265da0db479270a 这大概是个序 关于Three.js,网上有不多 ...