MZOJ 1345 hero
一道宽搜模版题,可写错了两个地方的我只得了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的更多相关文章
- H5游戏开发之Stick Hero
自从上次发布一个小恐龙游戏以后,到现在10天了,前后又写了3个游戏,挑了一个感觉比较有挑战的游戏和大家分享一下. 效果演示 这是我模拟一个苹果游戏<stick hero>游戏写的一个小游戏 ...
- BZOJ 1191 超级英雄 Hero 题解
BZOJ 1191 超级英雄 Hero 题解 Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金 ...
- 2016HUAS暑假集训训练2 K - Hero
题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...
- 【入门】匈牙利算法+HNOI2006 hero超级英雄
一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里( ...
- 2016HUAS_ACM暑假集训2K - Hero(英雄)
这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...
- bzoj 1191: [HNOI2006]超级英雄Hero
1191: [HNOI2006]超级英雄Hero Time Limit: 10 Sec Memory Limit: 162 MB 二分图匹配... Description 现在电视台有一种节目叫做超 ...
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- HDU4901 The Romantic Hero 计数DP
2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
随机推荐
- Windows配置Java环境
https://jingyan.baidu.com/article/84b4f56598d88b60f7da3272.html
- Centos 下使用VLAN+Bridge 搭建KVM基础网络环境
一.使用环境介绍 宿主机上同时运行多网段虚拟机,为了解决宿主机网卡资源紧张问题,采用如下网络模式:(本实验vlan 105:192.168.5.x vlan108:192.168.8.x) 二. ...
- 关于MySQL数据库的备份方案
这里简单总结MySQL的备份分为3种:分为冷备份,逻辑备份,热备份. 1.冷备份: 一般主要用于非核心业务,这类业务一般都是允许业务中断的,冷备份的特点就是数度快,恢复时也最为简单.通常直接复物理文件 ...
- 二叉树的深度优先遍历与广度优先遍历 [ C++ 实现 ]
深度优先搜索算法(Depth First Search),是搜索算法的一种.是沿着树的深度遍历树的节点,尽可能深的搜索树的分支. 当节点v的所有边都己被探寻过,搜索将回溯到发现节点v的那条边的起始节点 ...
- echarts中间有字饼图Demo1
echarts链接:http://gallery.echartsjs.com/editor.html?c=xHy2vIPzLQ 代码: option = { backgroundColor: 'bla ...
- java String 中替换"\"为"\\"
表示路径的字符串 c:\work\test\afd.out, 要形成 c:\\work\\test\\afd.out 用 String str = strBsf.replaceAll(" ...
- will not be exported or published. Runtime ClassNotFoundExceptions may result.
在eclipse中加入某个jar包时,会出现Classpath entry XXX.jar will not be exported or published. Runtime ClassNotFou ...
- Exploring the world of Android :: Part 2
September 17th, 2009 by Tom van Zummeren | And I’m back! Reporting live on the glorious adventures i ...
- SpringMVC之controller篇1
概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...
- git 标签管理
发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一个快照 ...