要从0,0 点 跑到m,n点  路上会有k个堡垒发射子弹。有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒

能够上下左右或者站着不动 每步都须要消耗能量  一共同拥有eng个能量

先预处理出地图 用三维数组表示mp[x][y][time] time表示该时间的地图上储存不能走的点

然后就是普通BFS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <math.h>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val) memset(arr, val, sizeof(arr))
#define IN freopen ("in.txt" , "r" , stdin);
#define OUT freopen ("out.txt" , "w" , stdout);
typedef long long LL;
const int MAXN = 66666;//点数的最大值
const int MAXM = 20006;//边数的最大值
const int INF = 1101521204;
const int mod = 10000007;
int m,n,k,eng;
struct node
{
int x,y,v,t,f;
}kp[102];
struct node1
{
int x,y,step;
};
queue<node1>q;
int xx[5]={0,-1,1,0,0};
int yy[5]={0,0,0,-1,1};
bool vis[110][110][1009];
bool mp[110][110][1009];
bool point[110][110];
bool inmp(int x,int y)
{
if(x<0||x>m||y<0||y>n) return false;
return true;
}
int bfs(int x,int y)
{
node1 front,rear;
front.x=x,front.y=y,front.step=0;
while(!q.empty()) q.pop();
q.push(front);
while(!q.empty())
{
front=q.front();
front.step++;
q.pop();
for(int i=0;i<5;i++)
{
int dx=front.x+xx[i],dy=front.y+yy[i];
if(inmp(dx,dy)&&!mp[dx][dy][front.step]&&!point[dx][dy]&&!vis[dx][dy][front.step])
{
vis[dx][dy][front.step]=true;
if(dx==m&&dy==n) return front.step;//到达终点
if(front.step+1>eng) continue;
rear.x=dx,rear.y=dy,rear.step=front.step;
q.push(rear);
}
}
}
return -1;
}
int main()
{
// IN;
while(scanf("%d%d%d%d",&m,&n,&k,&eng)!=EOF)
{
cler(mp,false);
cler(vis,false);
cler(point,false);
for(int i=0;i<k;i++)
{
char c[3];
scanf("%s%d%d%d%d",c,&kp[i].t,&kp[i].v,&kp[i].x,&kp[i].y);
if(c[0]=='N') kp[i].f=1;
else if(c[0]=='S') kp[i].f=2;
else if(c[0]=='W') kp[i].f=3;
else if(c[0]=='E') kp[i].f=4;
point[kp[i].x][kp[i].y]=true;
}
for(int i=0;i<k;i++)
{
int dx=kp[i].x,dy=kp[i].y,v=kp[i].v,next=kp[i].f;
for(int j=1;j<=eng;j++)
{
int flag=0;
dx+=xx[next],dy+=yy[next];
if(!inmp(dx,dy)) break;
for(int l=0;l<v;l++)//路上有堡垒
{
if(point[dx-xx[next]*l][dy-yy[next]*l])
{
flag=1;break;
}
}
if(flag) break;
int x=j;
while(x<=eng)
{
mp[dx][dy][x]=true;//标记不能走
x+=kp[i].t;
}
}
}
int ans=bfs(0,0);
if(ans==-1)
printf("Bad luck!\n");
else printf("%d\n",ans);
}
return 0;
}

【搜索】 HDU 3533 Escape BFS 预处理的更多相关文章

  1. HDU 3533 Escape (BFS + 预处理)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. HDU 3533 Escape BFS搜索

    题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...

  3. HDU 3533 Escape bfs 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...

  4. HDU 3533 Escape(bfs)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  6. HDU 3533 Escape(BFS+预处理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 题目大意:给你一张n* m的地图,人在起点在(0,0)要到达终点(n,m)有k(k<=10 ...

  7. POJ-1077 HDU 1043 HDU 3567 Eight (BFS预处理+康拓展开)

    思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> ...

  8. 【算法系列学习】[kuangbin带你飞]专题二 搜索进阶 D - Escape (BFS)

    Escape 参考:http://blog.csdn.net/libin56842/article/details/41909459 [题意]: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消 ...

  9. HDU3533 Escape —— BFS / A*算法 + 预处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others)  ...

随机推荐

  1. Codeforces 766E

    题意:给一棵树(1e5),每个节点上有对应权值(0<=ai<=1e6)定义树上两个节点间的距离为路径中节点的异或,求所有节点对间的距离和(包括节点自身也作为节点对,距离为节点权值). 解题 ...

  2. 微信接口本地调试(IIS服务器)

    1.下载ngrok,并注册获得token.官网下载地址:https://ngrok.com/ 如果你是在官网下载的,到后面映射域名的时候会要求购买他们的服务. 这里我们用一个国内免费的ngrok服务器 ...

  3. node(koa)微信公众号接口认证

    使用微信测试号, 花生壳内网穿透 需要注意 token 两边都是自定义, 需要保持一致, const Koa = require('koa') const sha1 = require('sha1') ...

  4. html5——动画案例(时钟)

    1.秒钟转360度需要60s分60步 2.分针转360度需要3600s分60步 3.秒钟转360度需要43200s分60步 <!DOCTYPE html> <html lang=&q ...

  5. Python 之__slots__的作用

    # 注意:__slots__ 用来限制当前类的实例属性的,如:name.age才可被使用,添加其他的属性则报错 # 不会限制继承类的属性 class Person(): __slots__ = (&q ...

  6. cocos自动图集

    对于图像资源,为什么要用图集,cocos官网的解释: 1.合成图集时会去除每张图片周围的空白区域,加上可以在整体上实施各种优化算法,合成图集后可以大大减少游戏包体和内存占用2.多个 Sprite 如果 ...

  7. 用jquery-easyui的布局layout写后台管理页面

    先在官网下载easyui文档 引入头部文件 <link rel="stylesheet" type="text/css" href="${pag ...

  8. JS数组reduce()方法

    1.语法 arr.reduce(callback,[initialValue]) reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被删除或从未被赋值的元素,接受四个参数:初始值(或者上 ...

  9. SpringBoot启动报jdbc连接池错误

    如图,启动报连接池错误 项目中没有使用任何连接池,以为没用连接池的原因,所以配置了druid,一开始可以正常启动,但后来重启项目时仍旧报同样的错.网上找了资料,url中加useSSL=false,显式 ...

  10. 洛谷——P2341 [HAOI2006]受欢迎的牛//POJ2186:Popular Cows

    P2341 [HAOI2006]受欢迎的牛/POJ2186:Popular Cows 题目背景 本题测试数据已修复. 题目描述 每头奶牛都梦想成为牛棚里的明星.被所有奶牛喜欢的奶牛就是一头明星奶牛.所 ...