HDU-2533:Escape
来源:互联网 发布:威尼斯 知乎 编辑:程序博客网 时间:2024/06/15 20:12
The students of the HEU are maneuvering for their military training.
The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to escape from the headquarters of the blue army to that of the red army. The battle field is a rectangle of size m*n, and the headquarters of the blue army and the red army are placed at (0, 0) and (m, n), respectively, which means that Little A will go from (0, 0) to (m, n). The picture below denotes the shape of the battle field and the notation of directions that we will use later.
The blue army is eager to revenge, so it tries its best to kill Little A during his escape. The blue army places many castles, which will shoot to a fixed direction periodically. It costs Little A one unit of energy per second, whether he moves or not. If he uses up all his energy or gets shot at sometime, then he fails. Little A can move north, south, east or west, one unit per second. Note he may stay at times in order not to be shot.
To simplify the problem, let’s assume that Little A cannot stop in the middle of a second. He will neither get shot nor block the bullet during his move, which means that a bullet can only kill Little A at positions with integer coordinates. Consider the example below. The bullet moves from (0, 3) to (0, 0) at the speed of 3 units per second, and Little A moves from (0, 0) to (0, 1) at the speed of 1 unit per second. Then Little A is not killed. But if the bullet moves 2 units per second in the above example, Little A will be killed at (0, 1).
Now, please tell Little A whether he can escape.
The red army and the blue army are at war today. The blue army finds that Little A is the spy of the red army, so Little A has to escape from the headquarters of the blue army to that of the red army. The battle field is a rectangle of size m*n, and the headquarters of the blue army and the red army are placed at (0, 0) and (m, n), respectively, which means that Little A will go from (0, 0) to (m, n). The picture below denotes the shape of the battle field and the notation of directions that we will use later.
The blue army is eager to revenge, so it tries its best to kill Little A during his escape. The blue army places many castles, which will shoot to a fixed direction periodically. It costs Little A one unit of energy per second, whether he moves or not. If he uses up all his energy or gets shot at sometime, then he fails. Little A can move north, south, east or west, one unit per second. Note he may stay at times in order not to be shot.
To simplify the problem, let’s assume that Little A cannot stop in the middle of a second. He will neither get shot nor block the bullet during his move, which means that a bullet can only kill Little A at positions with integer coordinates. Consider the example below. The bullet moves from (0, 3) to (0, 0) at the speed of 3 units per second, and Little A moves from (0, 0) to (0, 1) at the speed of 1 unit per second. Then Little A is not killed. But if the bullet moves 2 units per second in the above example, Little A will be killed at (0, 1).
Now, please tell Little A whether he can escape.
All castles begin to shoot when Little A starts to escape.
Proceed to the end of file.
4 4 3 10N 1 1 1 1W 1 1 3 2W 2 1 2 44 4 3 10N 1 1 1 1W 1 1 3 2W 1 1 2 4
9Bad luck!
注意四点:
1.人不能到达炮塔所在的坐标
2.炮塔会挡住子弹
3.途中遇到子弹是安全的,但是人如果停在这个坐标,而子弹也刚好到这个坐标,人就被射死
4.人可以选择停止不动
那么剩下的就是简单BFS了,还有由于数组较大,开int会MLE所以开bool
#include <bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 102;bool vist[maxn][maxn][1002];int m,n,k,d,t,v,x,y;int dx[5]={0,0,0,1,-1};int dy[5]={0,1,-1,0,0};char C[3];struct castles{//记录碉堡的信息 int v,t; int is; char c;}Point[maxn][maxn];struct node{//记录人的状态 int x,y; int step;}U,V;bool judge(node a){//判断该位置是否合法 if(a.x>=0 && a.x<=n && a.y>=0 && a.y <= m && !vist[a.x][a.y][a.step]) return true; return false;}void BFS(){ U.x = U.y = U.step = 0; queue<node>Q; Q.push(U); vist[0][0][0] = true; int flag,dis,cnt; while(!Q.empty()){ U = Q.front(); Q.pop(); if(U.step>d)//人的能量为零就结束 break; if(U.x == n && U.y == m){//可以顺利回到红军基地 printf("%d\n",U.step); return; } for(int i = 0; i < 5; i++){//枚举5种状态 V.x = U.x+dx[i]; V.y = U.y+dy[i]; V.step = U.step+1; if(!judge(V)) continue; if(!Point[V.x][V.y].is && V.step <= d){//碉堡的位置不能走,人没能量不能走 flag = 1; for(int j = V.x-1; j >= 0; j--){ if(Point[j][V.y].is && Point[j][V.y].c == 'S'){//人的北方第一个射击方向为南的碉堡 dis = V.x-j;//人与碉堡的距离 if(dis%Point[j][V.y].v == 0){//这个位置可能会被射击到 cnt = V.step-dis/Point[j][V.y].v;//时间差 if(cnt < 0)//子弹还没到 break; if(cnt%Point[j][V.y].t == 0){//射死 flag = 0; break; } } else//如果死不了就不用枚举这个方向其他的了碉堡了,因为子弹无法射过碉堡(还有这种操作)! break; } if(Point[j][V.y].is)//如果第一个碉堡方向不为南也不用枚举这个方向其他的了碉堡了,理由同上。 break; } if(!flag)//如果死了就不用枚举下面的方向的情况了。 continue; for(int j = V.x+1; j <= n; j++){ if(Point[j][V.y].is && Point[j][V.y].c == 'N'){ dis = j-V.x; if(dis%Point[j][V.y].v == 0){ cnt = V.step-dis/Point[j][V.y].v; if(cnt < 0) break; if(cnt%Point[j][V.y].t == 0){ flag = 0; break; } } else break; } if(Point[j][V.y].is) break; } if(!flag) continue; for(int j = V.y-1; j >= 0; j--){ if(Point[V.x][j].is && Point[V.x][j].c == 'E'){ dis = V.y-j; if(dis%Point[V.x][j].v == 0){ cnt = V.step-dis/Point[V.x][j].v; if(cnt < 0) break; if(cnt%Point[V.x][j].t == 0){ flag = 0; break; } } else break; } if(Point[V.x][j].is) break; } if(!flag) continue; for(int j = V.y+1; j <= m; j++){ if(Point[V.x][j].is && Point[V.x][j].c == 'W'){ dis = j-V.y; if(dis%Point[V.x][j].v == 0){ cnt = V.step-dis/Point[V.x][j].v; if(cnt < 0) break; if(cnt%Point[V.x][j].t == 0){ flag = 0; break; } } else break; } if(Point[V.x][j].is) break; } if(!flag) continue; vist[V.x][V.y][V.step] = true; Q.push(V); } } } puts("Bad luck!");}int main(){ while(~scanf("%d %d %d %d",&n,&m,&k,&d)){ memset(Point,0,sizeof(Point)); memset(vist,false,sizeof(vist)); for(int i = 0; i < k; i++){ scanf("%s %d %d %d %d",C,&t,&v,&x,&y); Point[x][y].t = t;//子弹的射击周期 Point[x][y].v = v;//子弹的速度 Point[x][y].is = 1;//是否是碉堡 Point[x][y].c = C[0]; } BFS(); } return 0;}
阅读全文
0 0
- HDU-2533:Escape
- hdu Escape
- Escape HDU
- Escape HDU
- Escape HDU
- Escape HDU
- hdu 1733 Escape
- hdu 1733 Escape
- Hdu 3605 Escape
- Hdu 3605 Escape
- BFS-hdu-3533-Escape
- HDU 3533 Escape
- HDU 3533 Escape
- HDU - 2364 Escape
- HDU 2364 Escape
- HDU-3533-Escape(BFS)
- HDU 3605 Escape
- hdu Escape(bfs+模拟)
- MFC子窗口向父窗口发送消息(测试成功20110117)
- 1097. Deduplication on a Linked List (25)
- 超级课程表课表的界面的实现
- [ax]WebBrowser.ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt) 参数列表及说明
- Win7 64bit 安装tensorflow,使用集成环境Anaconda和Pycharm
- HDU-2533:Escape
- 百度编辑器出现实体字符
- 二、矩阵的掩膜操作
- 前端学习
- 将含有pandas、numpy 等c源码包的代码打包为exe时出现错误的解决方法
- goLang引入自定义包
- datatables 按钮列(给按钮列的函数传值)
- countAndSayPlus
- 理解浮动以及解决浮动带来的问题