hdu 1242 Resuce
来源:互联网 发布:杭州的医疗大数据公司 编辑:程序博客网 时间:2024/06/05 20:10
题意:X代表卫兵,a代表终点,r代表起始点,.代表路,#代表墙
路花费一秒,x花费两秒
问到达终点的最少时间
思路:BFS+优先队列的果题
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cstdlib>#include <algorithm>#include <cmath>#include <set>#include <list>#include <queue>using namespace std;#define L(i) i<<1#define R(i) i<<1|1#define INF 0x3f3f3f3f#define pi acos(-1.0)#define maxn 100010#define mem(a) memset(a,0,sizeof(a))const double eps = 1e-10;char map[210][210];int vis[210][210];int n,m,ans,sx,sy,ax,ay;int mx[4] = {0,0,1,-1};int my[4] = {1,-1,0,0};struct node{ int x,y,t; node(int x,int y,int t):x(x),y(y),t(t){} bool operator <(const node a) const { return t > a.t; }};void bfs(){ node st(sx,sy,0); priority_queue<node> q; q.push(st); while(!q.empty()) { st = q.top(); q.pop(); if(st.x == ax && st.y == ay) { printf("%d\n",st.t); return; } for(int i = 0; i < 4; i++) { int dx = st.x + mx[i]; int dy = st.y + my[i]; if(dx < 0 || dx >= n || dy < 0 || dy >= m) continue; if(map[dx][dy] == '#') continue; if(vis[dx][dy]) continue; vis[dx][dy] = 1; node ss(dx,dy,st.t+1); if(map[dx][dy] == 'x') ss.t++; q.push(ss); } } printf("Poor ANGEL has to stay in the prison all his life.\n");}int main(){ while(scanf("%d%d",&n,&m) != EOF) { for(int i = 0; i < n; i++) scanf("%s",map[i]); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) { if(map[i][j] == 'a') { ax = i; ay = j; } if(map[i][j] == 'r') { sx = i; sy = j; } } mem(vis); bfs(); } return 0;}
0 0
- hdu 1242 Resuce
- LINUX RESUCE
- linux resuce模式介绍
- ZOJ 1649 Resuce (BFS)
- TCP offload to the resuce 让TCP减负来挽救我们
- windows与linux双系统,删除linux分区后,开机进入grub resuce提示符的问题
- 大数据 (十二)Hadoop-MR执行环境之---定义多个resuce task
- hdu 1242
- hdu 1242
- HDU 1242
- hdu 1242
- hdu-1242
- HDU 1242
- hdu--1242
- HDU 1242
- HDU 1242
- HDU 1242
- hdu 1242
- C#学习日记24----事件(event)
- android - failed to pull a selection
- 【hihocoder】1237 : Farthest Point ->微软2016校招在线笔试题
- C/C++编程题之找出2个给定字符串中最长的公共子字符串
- android 加载大图片到内存
- hdu 1242 Resuce
- 设置python路径
- 1015. Reversible Primes
- 仿CSDN安卓客户端(三)-----利用Xlistview讲目录中的数据显示出来
- iOS开发者必备:四款后端服务工具
- 意大利学习笔记开篇
- 黑马程序员——集合
- NIM 博弈游戏
- load和initialize的区分