bfs+优先队列。wa了N次,才发现可以停留等待楼梯变换方向。

 #include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std; #define MAXNUM 55 typedef struct node_st {
int x, y, t;
node_st() {}
node_st(int xx, int yy, int tt) {
x = xx; y = yy; t = tt;
}
friend bool operator < (node_st a, node_st b) {
return a.t > b.t;
}
} node_st; char map[MAXNUM][MAXNUM];
char visit[MAXNUM][MAXNUM];
int n, m;
int begx, begy, endx, endy;
int direct[][] = {{,},{-,},{,},{,-}}; int bfs(int begx, int begy) {
priority_queue<node_st> que;
node_st node;
int i, x, y, nx, ny, t; que.push(node_st(begx, begy, ));
memset(visit, , sizeof(visit));
visit[begx][begy] = ; while ( !que.empty() ) {
node = que.top();
if (map[node.x][node.y] == 'T') {
return node.t;
}
que.pop();
for (i=; i<; ++i) {
x = node.x + direct[i][];
y = node.y + direct[i][];
if (x< || x>=n || y< || y>=m)
continue;
if (visit[x][y] || map[x][y] == '*')
continue;
if (map[x][y] == '.' || map[x][y]=='T') {
que.push(node_st(x,y,node.t+));
visit[x][y] = ;
continue;
}
if (map[x][y]=='|' || map[x][y]=='-') {
nx = x + direct[i][];
ny = y + direct[i][];
t = node.t + ;
if (nx< || nx>=n || ny< || ny>=m)
continue;
if (visit[nx][ny] || map[nx][ny]=='*')
continue;
if ( ((map[x][y]=='|') && ((node.t&)==) && (i==||i==)) ||
((map[x][y]=='|') && ((node.t&)!=) && (i==||i==)) ||
((map[x][y]=='-') && ((node.t&)==) && (i==||i==)) ||
((map[x][y]=='-') && ((node.t&)!=) && (i==||i==)) )
++t;
visit[nx][ny] = ;
que.push(node_st(nx, ny, t));
}
}
} return -;
} int main() {
int i, j; while (scanf("%d %d%*c",&n,&m) != EOF) {
for (i=; i<n; ++i) {
scanf("%s", map[i]);
for (j=; j<m; ++j) {
if (map[i][j] == 'S') {
begx = i;
begy = j;
}
}
}
i = bfs(begx, begy);
printf("%d\n", i);
} return ;
}

【HDOJ】1180 诡异的楼梯的更多相关文章

  1. HDU 1180 诡异的楼梯(超级经典的bfs之一,需多回顾)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1180 诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)     ...

  2. hdu 1180 诡异的楼梯

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  3. hdu 1180 诡异的楼梯 (bfs)

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Sub ...

  4. HDU 1180 诡异的楼梯(BFS)

    诡异的楼梯 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status ...

  5. hdu 1180诡异的楼梯(bfs)

    诡异的楼梯 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submis ...

  6. hdu 1180:诡异的楼梯(BFS广搜)

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  7. HDU 1180 诡异的楼梯【BFS/楼梯随时间变化】

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submis ...

  8. HDOJ/HDU 1180 诡异的楼梯(经典BFS-详解)

    Problem Description Hogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向. 比如下面的例子里,一开始楼梯在 ...

  9. hdu - 1180 诡异的楼梯 (bfs+优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=1180 注意点就是楼梯是在harry移动完之后才会改变方向,那么只要统计到达这个点时间奇偶性,就可以知道当前楼梯是 ...

随机推荐

  1. (转)ASP.net中Timer无刷新定时器.

    Timer控件要实现无刷新,得用到ajax技术 首先得添加一个ScriptManager控件,然后再添加一个UpdatePanel用于存放Timer控件内容的,就可以实现无刷新了.下面是详细的内容: ...

  2. 20151215jquery学习笔记--jqueryUI --dialog(对话框)

    对话框(dialog),是 jQuery UI 非常重要的一个功能.它彻底的代替了 JavaScript 的 alert().prompt()等方法,也避免了新窗口或页面的繁杂冗余 一.开启多个 di ...

  3. Linux的各种命令(android adb shell)

    win+r 调出运行,输入CMD adb shell 进入手机的控制终端,相当于原生的Linux系统的各种操作. 当提示符为$符号,说明未获得超级管理员权限,输入su,可编程# adb kill-se ...

  4. sqlserver临时表排序问题

    在2005和2008中,如果将有序的记录插入临时表,则从临时表查看出来的记录是有序的(不使用Order by也是有序状态) 但从2012开始,即使插入的记录集是有序的,查看出来的结果变得无序了,需要依 ...

  5. SEVERE: Class [ com/mysema/query/dml/DeleteClause ] not found

    SEVERE:   Class [ com/mysema/query/dml/DeleteClause ] not found. Error while loading [ class org.spr ...

  6. 添加samba用户,并设置密码

    5.3.3 添加samba用户,并设置密码; 我们用的方法是先添加用户,但添加的这些用户都是虚拟用户,因为这些用户是不能通过SHELL登录系统的;另外值得注意的是系统用户密码和Samba用户的密码是不 ...

  7. ORACLE no1 存储过程插入更新表数据

    CREATE OR REPLACE PROCEDURE sp_cust_main_data_yx(InStrDate  IN VARCHAR2,                             ...

  8. xpath选择器

    一.xpath中节点关系 父(Parent):每个元素以及属性都有一个父 子(Children):元素节点可有零个.一个或多个子 同胞(Sibling):拥有相同的父的节点 先辈(Ancestor): ...

  9. javascript 函数学习

    1.自以为好的部分,更多访问: http://www.runoob.com/js/js-tutorial.html 2.this 3.new 4.闭包 5.自执行

  10. 12_复杂查询01_Mapper代理实现

    [工程截图] [代码实现] [user.java] package com.Higgin.Mybatis.po; import java.util.Date; public class User { ...