BFS。

 /* 1484 */
#include <iostream>
#include <queue>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef struct {
int x, y;
string s;
} node_t; bool m[][][];
bool visit[][];
char ds[] = "NSWE";
int dir[][] = {
-,,,,,-,,
}; const int n = ;
int bx, by, ex, ey;
string ans; void bfs() {
int x = bx, y = by;
int i, j, k;
queue<node_t> Q;
string s;
node_t nd, tmp; memset(visit, false, sizeof(visit));
visit[x][y] = true;
nd.x = x;
nd.y = y;
nd.s = "";
Q.push(nd); while (!Q.empty()) {
nd = Q.front();
Q.pop();
for (i=; i<; ++i) {
if (m[nd.x][nd.y][i])
continue;
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (x<= || x> || y<= || y> || visit[x][y])
continue;
visit[x][y] = true;
tmp.x = x;
tmp.y = y;
tmp.s = nd.s + ds[i];
if (x==ex && y==ey) {
ans = tmp.s;
return ;
}
Q.push(tmp);
}
}
} int main() {
int i, j, k;
int x, y;
int a, b, c, d; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d %d",&by,&bx)!=EOF && (by||bx)) {
scanf("%d %d", &ey, &ex);
memset(m, false, sizeof(m));
for (i=; i<; ++i) {
scanf("%d%d%d%d", &a,&b,&c,&d);
if (b == d) {
// north & south need to mask
for (y=a+; y<=c; ++y) {
m[b][y][] = true;
m[b+][y][] = true;
}
} else {
// west & east need to mask
for (x=b+; x<=d; ++x) {
m[x][a][] = true;
m[x][a+][] = true;
}
}
}
bfs();
printf("%s\n", ans.c_str());
} return ;
}

【HDOJ】1484 Basic wall maze的更多相关文章

  1. HDU 1484 Basic wall maze (dfs + 记忆)

    Basic wall maze Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. 【HDOJ】1315 Basic

    这道题目巨坑啊,注意__int64,int wa了一个下午. #include <cstdio> #include <cstring> #include <cstdlib ...

  3. poj-2935 BFS Basic Wall Maze

    Basic Wall Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3384   Accepted: 1525   ...

  4. 【LeetCode】227. Basic Calculator II 解题报告(Python)

    [LeetCode]227. Basic Calculator II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...

  5. 【LeetCode】554. Brick Wall 解题报告(Python)

    [LeetCode]554. Brick Wall 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

  6. 【HDOJ】1348 Wall

    计算几何-凸包模板题目,Graham算法解. /* 1348 */ #include <iostream> #include <cstdio> #include <cst ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  8. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  9. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

随机推荐

  1. spring session工程发布--一种新的管理httpsession的方法

    官方文档:http://spring.io/blog/2014/07/08/spring-session-1-0-0-m1-released 1. 优点: This project provides ...

  2. WPF DataGrid某列使用多绑定后该列排序失效,列上加入 SortMemberPath 设置即可.

    WPF DataGrid某列使用多绑定后该列排序失效 2011-07-14 10:59hdongq | 浏览 1031 次  悬赏:20 在wpf的datagrid中某一列使用了多绑定,但是该列排序失 ...

  3. 'Service' object has no attribute 'process'

    在使用selenium+phantomjs时,运行总是出现错误信息: 'Service' object has no attribute 'process' 出现该错误的原因是未能找到可执行程序&qu ...

  4. json 序列化的两种方式

    JavaScriptSerializer Serializer = new JavaScriptSerializer(); ResultData<EUserData> resultMode ...

  5. CSS3 变形小结

    为原始大小 b:纵向扭曲,0为不变 c :横向扭曲,0不变 d:垂直伸缩量,1为原始大小 e:水平偏移量,0为初始位置 f  :垂直偏移向,0是初始位置 Ø原点 transform-origin() ...

  6. zabbix 基于JMX的Tomcat监控

    zabbix 基于JMX的Tomcat监控 一.环境 ubuntu14.04 LTS Java 1.7.0 zabbix 2.4.5 二.安装配置 1.安装JavaGateway 在ubuntu14. ...

  7. linux常用命令之ln

    ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件. 当我们需要在不同的目录,用到相同的 ...

  8. UIView下使用Animation控制动画

    转载自:http://blog.csdn.net/xunyn/article/details/8128031 动画效果是IOS界面重要的特色之一,其中CAAnimation是所有动画对象的抽象父类,作 ...

  9. SGU 114.Telecasting station

    题意: 百慕大的每一座城市都坐落在一维直线上.这个国家的政府决定建造一个新的广播电视台.经过了许多次试验后,百慕大的科学家们提出了一个结论,在每座城市的不满意度等于这座城市的市民数与这座城市与广播电视 ...

  10. SGU 131.Hardwood floor

    时间限制:0.25s 空间限制:4M 题意: 给出 n*m (1≤n.m≤9)的方格棋盘,用 1*2 的矩形的骨牌和 L 形的(2*2 的 去掉一个角)骨牌不重叠地覆盖,求覆盖满的方案数. Solut ...