题意:懒得说了

分析:开个no[100][100][1000]的bool类型的数组就行了,没啥可说的

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
const int N=;
int n,m,k,d,l;
struct node
{
char s[];
int x,y,v,t;
} o[N];
bool mp[N][N];
bool no[N][N][];
void No(int pos)
{
l=;
for(int i=o[pos].x-; i>=; --i)
if(mp[i][o[pos].y])
{
l=i+;
break;
}
for(int i=; i<=d; i+=o[pos].t)
{
int now=o[pos].x-o[pos].v;
for(int j=i+; j<=d&&now>=l; ++j,now-=o[pos].v)
no[now][o[pos].y][j]=;
}
}
void S(int pos)
{
l=n;
for(int i=o[pos].x+; i<=n; ++i)
if(mp[i][o[pos].y])
{
l=i-;
break;
}
for(int i=; i<=d; i+=o[pos].t)
{
int now=o[pos].x+o[pos].v;
for(int j=i+; j<=d&&now<=l; ++j,now+=o[pos].v)
no[now][o[pos].y][j]=;
}
}
void W(int pos)
{
l=;
for(int i=o[pos].y-; i>=; --i)
if(mp[o[pos].x][i])
{
l=i+;
break;
}
for(int i=; i<=d; i+=o[pos].t)
{
int now=o[pos].y-o[pos].v;
for(int j=i+; j<=d&&now>=l; ++j,now-=o[pos].v)
no[o[pos].x][now][j]=;
}
}
void E(int pos)
{
l=m;
for(int i=o[pos].y+; i<=m; ++i)
if(mp[o[pos].x][i])
{
l=i-;
break;
}
for(int i=; i<=d; i+=o[pos].t)
{
int now=o[pos].y+o[pos].v;
for(int j=i+; j<=d&&now<=l; ++j,now+=o[pos].v)
no[o[pos].x][now][j]=;
}
}
struct asd
{
int x,y,w;
} a,e;
int dx[]= {,,,,-};
int dy[]= {,-,,,};
queue<asd>q;
int bfs()
{
while(!q.empty())q.pop();
q.push(asd {,,});
no[][][]=;
while(!q.empty())
{
a=q.front();
q.pop();
for(int i=; i<; ++i)
{
e.x=a.x+dx[i];
e.y=a.y+dy[i];
e.w=a.w+;
if(e.x<||e.x>n||e.y<||e.y>m)continue;
if(e.w>d)continue;
if(mp[e.x][e.y])continue;
if(no[e.x][e.y][e.w])continue;
if(e.x==n&&e.y==m)return e.w;
no[e.x][e.y][e.w]=;
q.push(e);
}
}
return -;
}
int main()
{
while(~scanf("%d%d%d%d",&n,&m,&k,&d))
{
memset(mp,,sizeof(mp));
memset(no,,sizeof(no));
for(int i=; i<=k; ++i)
{
scanf("%s%d%d%d%d",o[i].s,&o[i].t,&o[i].v,&o[i].x,&o[i].y);
mp[o[i].x][o[i].y]=;
}
int ans=;
if(mp[][]||mp[n][m])
ans=-;
if(ans!=-)
for(int i=; i<=k; ++i)
{
if(o[i].s[]=='N')No(i);
else if(o[i].s[]=='S')S(i);
else if(o[i].s[]=='W')W(i);
else E(i);
}
if(ans!=-)ans=bfs();
if(ans==-)printf("Bad luck!\n");
else printf("%d\n",ans);
}
return ;
}

HDU 3533 Escape BFS搜索的更多相关文章

  1. 【搜索】 HDU 3533 Escape BFS 预处理

    要从0,0 点 跑到m,n点  路上会有k个堡垒发射子弹.有子弹的地方不能走,子弹打到别的堡垒就会消失,或者一直飞出边界(人不能经过堡垒 能够上下左右或者站着不动 每步都须要消耗能量  一共同拥有en ...

  2. HDU 3533 Escape bfs 难度:1

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

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

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

  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. HDU 1495 非常可乐 BFS 搜索

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...

  8. HDU 1495 非常可乐 BFS搜索

    题意:有个为三个杯子(杯子没有刻度),体积为s,n,m,s=m+n, 刚开始只有体积为s的杯子装满可乐,可以互相倒,问你最少的次数使可乐均分,如果没有结果,输出-1; 分析:直接互相倒就完了,BFS模 ...

  9. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. XSS 复合编码 续

    对上文 [web安全]第二弹:XSS攻防中的复合编码问题 的一些补充,思路来源于:http://escape.alf.nu/3/ html解码的问题: 通过appendChild添加的节点,不会被HT ...

  2. linux du 与 df 命令

    du 命令:显示每个文件和目录的磁盘使用空间 命令格式:du [选项][文件] -k或--kilobytes  以KB(1024bytes)为单位输出. -m或--megabytes  以MB为单位输 ...

  3. IOS调用相机和相册时无法显示中文

    调用系统相册.相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文 需要在info.plist做如下设置 info.plist里面添加 Localizedresourc ...

  4. PD name 和 comment 互换

    1 PowerDesigner中批量根据对象的name生成comment的脚本 执行方法:Open PDM -- Tools -- Execute Commands -- Run Script --- ...

  5. 增强LSH

    通过LSH hash functions我们能够得到一个或多个hash table,每个桶内的数据之间是近邻的可能性很大.我们希望原本相邻的数据经过LSH hash后,都能够落入到相同的桶内,而不相邻 ...

  6. zoj 2387

    额  一个贪心  好难想到 ...... #include <cstring> #include <cstdio> #include <algorithm> #in ...

  7. FZU-1926+KMP

    题意:给定一篇文章和一些句子.询问句子是否在文章中出现. kmp模板题 /* kmp */ #include<stdio.h> #include<string.h> #incl ...

  8. HDU4602+推导公式

    手动列出前5项 可发现规律 /* 推导公式 a[n] = 2^(n-1) + (n-2)*2^(n-3) */ #include<stdio.h> #include<math.h&g ...

  9. MetadataType的使用

    MetadataType的使用,MVC的Model层数据验证指定要与数据模型类关联的元数据类 using System.ComponentModel.DataAnnotations; //指定要与数据 ...

  10. highChartTable 切换

    <!doctype html> <html lang="en"> <head> <script type="text/javas ...