【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[ ...
随机推荐
- [转] Express 4 中的变化
http://www.cnblogs.com/haogj/p/3985438.html 概览 从 Express 3 到Express 4 是一个巨大的变化,这意味着现存的 Express 3 应用在 ...
- iOS UIKit:viewController之动画(5)
当弹出一个view controller时,UIKit提供了一些标准转换动画,并且也支持用户自定义的动画效果. 1 UIView动画 UIView是自带动画实现功能,其中有两种方式实现: ...
- oracle实现自动记录存储过程、自定义函数执行错误
CREATE OR REPLACE Package Pkg_Stm_Prgerrlog As --Purpose: 实现记录系统错误异常信息,便于问题跟踪 Procedure Sp_Stm_Prger ...
- 9.20 noip模拟试题
Problem 1 双色球(ball.cpp/c/pas) [题目描述] 机房来了新一届的学弟学妹,邪恶的chenzeyu97发现一位学弟与他同名,于是他当起了善良的学长233 “来来来,学弟,我 ...
- 关于SqlServer修改数据库常用信息的方法
--系统表里存放各个数据库属性信息的表之一SELECT name AS [Logical Name], physical_name AS [DB File Path],type_desc AS [Fi ...
- (转)function($){}(window.jQuery) 是什么意思?
function(){}(); (function(){})(); 这两个是self-invoking anonymous 自调匿名函数,用这类的方法,能强制使匿名函数成为表达式,把不合法变成合法. ...
- C#中的三种 加密解密
刚刚学会的C#的加密与解密(三种)MD5加密/RSA加密与解密/DES加密.也是刚刚申请的blog随便发布一下. (一).MD5加密 MD5 md5 = new MD5CryptoServicePro ...
- WPF TextSelection获取选中部分内容
一.简单实例 //TextSelect继承自TextRange TextSelection selection = richTextBox.Selection; //1.获取选中内容 string r ...
- JAVA JDK 1.6 API中文版.CHM打开chm提示,“ 已取消到该网页的导航”
JAVA JDK 1.6 API中文版.CHM打开chm提示,“ 已取消到该网页的导航” silent fish 装了win7后,打开chm文件,发现很多在xp系统打开正常的chm文件竟然出现问题, ...
- runnable和thread的区别
一是写一个类继承自Thread类,然后重写里面的run方法,用start方法启动线程二是写一个类实现Runnable接口,实现里面的run方法,用new Thread(Runnable target) ...