【HDOJ】1484 Basic wall maze
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的更多相关文章
- HDU 1484 Basic wall maze (dfs + 记忆)
Basic wall maze Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【HDOJ】1315 Basic
这道题目巨坑啊,注意__int64,int wa了一个下午. #include <cstdio> #include <cstring> #include <cstdlib ...
- poj-2935 BFS Basic Wall Maze
Basic Wall Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3384 Accepted: 1525 ...
- 【LeetCode】227. Basic Calculator II 解题报告(Python)
[LeetCode]227. Basic Calculator II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
- 【LeetCode】554. Brick Wall 解题报告(Python)
[LeetCode]554. Brick Wall 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- 【HDOJ】1348 Wall
计算几何-凸包模板题目,Graham算法解. /* 1348 */ #include <iostream> #include <cstdio> #include <cst ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
随机推荐
- CentOS6安装配置rsh
基本信息:节点一:ip:192.168.8.166 主机名:hadrtest01节点二:ip:192.168.8.250 主机名:hadrtest02 1.两节点分别安装rsh,rsh-server包 ...
- C#开发学习——内联表达式
<%@ 表示:引用 <%# 表示:绑定 <%= 表示:取值 <%= 变量名%> Response.Write()输出和<%=%>输出最后的效果是一样的 ...
- Android Camera开发:使用TextureView和SurfaceTexture预览Camera 基础拍照demo
Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...
- 关于Entity Framework 5 从数据库生成模型时没有字段注释的解决方法!
目前用到了EF5进行模型创建,发现从数据库生成过来的实体中并没有包含字段的说明信息(鄙视下微软,这么简单的问题都不给解决下,太粗枝大叶了),网上找到了EFTSQLDocumentation.Gener ...
- C#生成验证码实例
常用生成验证码实例封装: /// <summary> /// 生成内存位图 /// </summary> /// <param name="Code" ...
- Android之获取本地图片并压缩方法
这两天在做项目时,做到上传图片功能一块时,碰到两个问题,一个是如何获取所选图片的路径,一个是如何压缩图片,在查了一些资料和看了别人写的后总算折腾出来了,在此记录一下. 首先既然要选择图片,我们就先要获 ...
- JSP自定义标签库
总所周知,JSP自定义标签库,主要是为了去掉JSP页面中的JAVA语句 此处以格式化输出时间戳为指定日期格式为例,简单介绍下JSP自定义标签的过程. 编写标签处理类(可继承自javax.servlet ...
- Wireshark提示没有一个可以抓包的接口
这是由于win下默认NPF服务是关闭的,需要以管理员的身份开启这个服务 Windows上安装wireshark时,会遇到NPF驱动无法启动的情况,一般如果采用管理员的方式就可以正常启动,或者是将NPF ...
- CI 笔记3 (easyui 的layout布局,最小化layout原型)
在做easyui的layout的布局时,最小化一个原型,分2步,一个是div的父标签,一个是body做父标签,全屏的. 步骤分别为: 在设置的5个区中,div的最后一个,必须是data-options ...
- index ffs、index fs原理考究-1109
h2 { margin-top: 0.46cm; margin-bottom: 0.46cm; direction: ltr; line-height: 173%; text-align: justi ...