【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[ ...
随机推荐
- XML解析技术研究(一)
摘要:XML作为过去十年中出现的最流行的技术之一,得到了广泛的应用,而其中XML解析技术是XML应用的关键.本文介绍了XML解析技术的研究动向,分析和比较了4种XML解析技术的优劣,并归纳总结了应 ...
- spring servlet 扩展undertow
官方地址:http://undertow.io/documentation/servlet/servlet-extensions.html 留待学习中,mark一下 源码地址:https://git ...
- Codeforces 552E - Vanya and Brackets【表达式求值】
给一个只有加号和乘号的表达式,要求添加一对括号使得最后结果最大.表达式长度5000,乘号最多12个,表达式中数字只有1位. 左括号一定在乘号右边,右括号一定在乘号左边,因为如果不是这样的话,一定可以调 ...
- js获取图片高度
js获取图片高度时经常会获取的图片高度为0,原因是图片未加载完毕.第一次加载时,显示0(火狐等部分浏览器显示24).待加载完毕后,再刷新,显示图片高度258. var oImg = document. ...
- jar包的生成及运行
Hello, 大家好,我们见面了,今天是2015年7月30日,我在青岛,你好吗? 这里总结下刚学习到的jar包的生成和运行,网上的资料一搜一大片,我这里总结下适用的 一:jar包的生成: 1:命令行, ...
- Socket 学习
Socket一般应用模式(服务器端和客户端) 服务器端Socket(至少有两个) ->一个负责接收客户端连接请求(但不负责和客户端通信) ->没成功接收到一个客户端的连接便在服务端生成一个 ...
- 【转】UILabel、UITextView自适应得到高度
原文:http://blog.csdn.net/xcysuccess3/article/details/8331549 在iOS中,经常遇到需要根据字符串的内容动态指定UILabel,UITextVi ...
- Java GC 日志输出分析
搜到的几篇讲GC日志的文章,学到了很多东西.但是有些错误或者不够精确的地方. 因此自己尝试着总结一下. 先写个程序,然后结合程序解释每句话的意思. 运行参数 -Xms200M -Xmx200M -Xm ...
- 不带头结点的单链表递归删除元素为X的结点
#include <iostream> using namespace std; struct Node { Node *next; int elem; }; void creatList ...
- 第四篇、Tomcat 集群
1. 前言 该篇中测试的机器发生了变更,在第一篇中设置的Apache DocumentRoot "d:/deployment"修改为了DocumentRoot d:/clust ...