栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1649 Rescue

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1649 Rescue

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <stack>#include <queue>#include <cmath>#include <algorithm>#define lson l, m, rt<<1#define rson m+1, r, rt<<1|1using namespace std;typedef long long int LL;const int MAXN =  0x3f3f3f3f;const int  MINN =  -0x3f3f3f3f;const double eps = 1e-9;const int dir[8][2] = {{0,1},{1,0},{0,-1},{-1,0},{-1,1},  {1,1},{1,-1},{-1,-1}};typedef struct point{  int a, b, t;}point;point p[220][220], st, en;char s[220][220];int n, m, T, si, sj, di, dj; queue<point> qt;void bfs(){  qt.push(st);  while (!qt.empty()){    point po = qt.front();    qt.pop();    for (int k = 0; k < 4; ++k){      int nexti=po.a+dir[k][0],nextj=po.b+dir[k][1];      if (nexti>=0&&nexti<=n&&nextj>=0&&nextj<=m&&s[nexti][nextj]!='#'){        int nowt = po.t+1; if(s[nexti][nextj]=='x') nowt++;        if (nowt<p[nexti][nextj].t){          p[nexti][nextj].t = nowt;          qt.push(p[nexti][nextj]);        }      }    }  }}int main(void){  while (~scanf("%d%d", &n, &m)){    getchar();    for (int i = 1; i <= n; ++i){      for (int j = 1; j <= m; ++j){        scanf("%c", &s[i][j]);        if (s[i][j] == 'r') {si = i; sj = j;}        else if (s[i][j] == 'a') {di = i; dj = j;}        p[i][j].t = MAXN; p[i][j].a = i; p[i][j].b = j;      } getchar();    }    st.a = si; st.b = sj; st.t = 0;    bfs();    if (p[di][dj].t == MAXN){      printf("Poor ANGEL has to stay in the prison all his life.n");    } else printf("%dn", p[di][dj].t);  } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377303.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号