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. 在GDB 中如何记录 instruction-history and function-call-history

    (EDIT: per the first answer below the current "trick" seems to be using an Atom processor. ...

  2. 『零行代码』解决键盘遮挡问题(iOS)

    关注仓库,及时获得更新:iOS-Source-Code-Analyze https://github.com/draveness/iOS-Source-Code-Analyze Follow: Dra ...

  3. Call Directory Extension 初探

    推荐序 本文介绍了 iOS 10 中的 Call Directory Extension 特性,并且最终 Demo 出一个来电黑名单的 App. 作者:余龙泽,哈工大软件工程大四学生,之前在美图公司实 ...

  4. 第二篇:python高级之装饰器

    python高级之装饰器   python高级之装饰器 本节内容 高阶函数 嵌套函数及闭包 装饰器 装饰器带参数 装饰器的嵌套 functools.wraps模块 递归函数被装饰 1.高阶函数 高阶函 ...

  5. JAVA学习笔记--二

    一.抽象类: 访问修饰符 abstract class 类名{ } 抽象类和普通类的区别: 1. 抽象类不能被实例化 2. 抽象类一般含有抽象方法 抽象方法:在抽象类中只有方法签名(方法声明),没有方 ...

  6. CSS美化 input type=file 兼容各个浏览器(转)

    HTML代码: <FORM> <A class=btn_addPic href="javascript:void(0);"><SPAN>< ...

  7. oracle批量导入数据

    关键代码 OracleDataAdapter da=new OracleDataAdapter(); string sql_select = string.Format("select id ...

  8. 谈谈oracle中的临时表

    --------------------创建临时表 临时保存从xml字符串解析来的数据--------------------------- 会话级别临时表SQL> create global ...

  9. iOS NSData简单解析

    iOS 基本数据类型之NSData 1 nsdata 作用: 用于存储二进制的数据类型 nadat类提供一种简单的方式,它用来设置缓存区.将文件的内容读入到缓存区.或者将缓存区中的内容写到一个文件. ...

  10. 关于typedef的用法总结

    不管实在C还是C++代码中,typedef这个词都不少见,当然出现频率较高的还是在C代码中.typedef与#define有些相似,但更多的是不同,特别是在一些复杂的用法上,就完全不同了,看了网上一些 ...