【搜索】 HDU 3533 Escape BFS 预处理
要从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 预处理的更多相关文章
- HDU 3533 Escape (BFS + 预处理)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 3533 Escape BFS搜索
题意:懒得说了 分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的 #include <iostream> #include <cstdio> ...
- HDU 3533 Escape bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...
- HDU 3533 Escape(bfs)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- HDU 3533 Escape(BFS+预处理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 题目大意:给你一张n* m的地图,人在起点在(0,0)要到达终点(n,m)有k(k<=10 ...
- POJ-1077 HDU 1043 HDU 3567 Eight (BFS预处理+康拓展开)
思路: 这三个题是一个比一个令人纠结呀. POJ-1077 爆搜可以过,94ms,注意不能用map就是了. #include<iostream> #include<stack> ...
- 【算法系列学习】[kuangbin带你飞]专题二 搜索进阶 D - Escape (BFS)
Escape 参考:http://blog.csdn.net/libin56842/article/details/41909459 [题意]: 一个人从(0,0)跑到(n,m),只有k点能量,一秒消 ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
随机推荐
- 使用HBuilder新建项目
依次点击文件→新建→选择Web项目(按下Ctrl+N,W可以触发快速新建(MacOS请使用Command+N,然后左键点击Web项目)) 如上图,请在A处填写新建项目的名称,B处填写(或选择)项目保存 ...
- Elasticsearch之CURL命令的GET
这是个查询命令. 前期博客 Elasticsearch之CURL命令的PUT和POST对比 1. 以上是根据员工id查询. 即在任意的查询字符串中添加pretty参数,es可以得到易于我们识别的jso ...
- node or gulp 使用
##MAC 升级node.js的方法 ###第一步,先查看本机node.js版本: $ node -v ###第二步,清除node.js的cache: $ sudo npm cache clean - ...
- pd_ds 之 hash
http://attack.cf/?post=23 打个广告....
- Server Tomcat v8.0 Server at localhost failed to start 问题解决方法?
bi编程jsp servlet 第一个程序: HelloServlet 运行错误 404: 十月 28, 2017 11:25:14 上午 org.apache.tomcat.util.digest ...
- 网络中 ping 不通 路由表
不管是在window还是在linux中,我们经常会遇到ping不通的问题. 这里的原因很多,比如不同的网段交换机做了一些限制等,这些问题是我们人工不能解决的. 但是,当你发现各自的网关是可以ping的 ...
- Java 基础入门随笔(1) JavaSE版——java语言三种技术架构
1.java语言的三种技术架构: J2SE(java 2 Platform Standard Edition):标准版,是为开发普通桌面和商务应用程序提供的解决方案.该技术体系是其他两者的基础,可以完 ...
- pycuda installation error: command 'gcc' failed with exit status 1
原文:python采坑之路 Setup script exited with error: command 'gcc' failed with exit status 1 伴随出现"cuda ...
- CAD增加一个有形的线型(网页版)
主要用到函数说明: _DMxDrawX::AddTextStyle1 向数据库中增加一个文字样式.详细说明如下: 参数 说明 BSTR pszName 文字样式名称 BSTR pszFileName ...
- CPU 指令集(Instruction Set Architecture, ISA)
本文摘自网络 概念 指令集是存储在CPU内部,对CPU运算进行指导和优化的硬程序,用来引导CPU进行加减运算和控制计算机操作系统的一系列指令集合.拥有这些指令集,CPU就可以更高效地运行.系统所下达的 ...