poj 1915 http://poj.org/problem?id=1915
/**< */#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <ctype.h>
#define N 310 using namespace std; int d[][] = {{-, -}, {-, }, {-, -}, {-, }, {, -}, {, }, {, -}, {, }};
int vis[N][N], l, ex, ey; struct node
{
int x, y, step;
}; int BFS(int x, int y)
{
queue<node>Q;
int i;
node now, next;
now.x = x;
now.y = y;
now.step = ;
vis[now.x][now.y] = ;
Q.push(now);
while(!Q.empty())
{
now = Q.front();
Q.pop();
if(now.x == ex && now.y == ey)
return now.step;
for(i = ; i < ; i++)
{
next.x = now.x + d[i][];
next.y = now.y + d[i][];
next.step = now.step + ;
if(next.x >= && next.x < l && next.y >= && next.y < l && !vis[next.x][next.y])
{
vis[next.x][next.y] = ;
Q.push(next);
}
}
}
return -;
} int main()
{
int t, sx, sy;
scanf("%d", &t);
while(t--)
{
memset(vis, , sizeof(vis));
scanf("%d", &l);
scanf("%d%d", &sx, &sy);
scanf("%d%d", &ex, &ey);
if(sx == ex && sy == ey)
printf("0\n");
else
printf("%d\n", BFS(sx, sy));
}
return ;
}
poj 1915 http://poj.org/problem?id=1915的更多相关文章
- poj 1651 http://poj.org/problem?id=1651
http://poj.org/problem?id=1651Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K To ...
- poj-3056 http://poj.org/problem?id=3056
http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS Memory Limit: 65536K Tot ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ3278http://poj.org/problem?id=3278
http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
- poj 1681 Painter's Problem(高斯消元)
id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- <挑战程序设计竞赛> poj 3320 Jessica's Reading Problem 双指针
地址 http://poj.org/problem?id=3320 解答 使用双指针 在指针范围内是否达到要求 若不足要求则从右进行拓展 若满足要求则从左缩减区域 代码如下 正确性调整了几次 然后 ...
随机推荐
- WIN7建立网络映射磁盘
建立网络映射磁盘 如果需要经常访问网络中的同一个共享文件夹,则可以将这个共享文件夹直接映射为本地计算机中的一个虚拟驱动器.其具体操作如下. (1)双击桌面上"计算机"图标,打开&q ...
- mysql 查看警告
显示警告(打开): warnings 查看警告(查看内容): show warnings; 记录运行日志: tee _logsfile source sql_filenotee
- Java Swing中Substance常用皮肤
AutumnSkin; BusinessSkin; BusinessBlackSteelSkin; BusinessBlueSteelSkin; ChallengerDeepSkin; CremeSk ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- Codeforces Round #271 (Div. 2)
A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...
- ios tweak之binary not signed (use ldid -S)问题解决
参考tweak教程写了个简单的tweak,无奈完全无效果,摸索了好长时间才找到方法: 打开terminal ssh root@192.168.1.100 vim /var/log/syslog 找到如 ...
- Oracle中将小数转换成字符丢零.截取小数.除数为零解决法
如下所示,前面少个0 SQL>select money from users where username ='LEI'; money --------- .3256 解决方法: SQL> ...
- java 中的Exception RuntimeException 区别
在java的异常类体系中: 1.Error和RuntimeException是非检查型异常,其他的都是检查型异常; 2.所有方法都可以在不声明throws的情况下抛出RuntimeException及 ...
- [Papers]NSE, $\p_3u$, Lebesgue space [Cao, DCDSA, 2010]
$$\bex \p_3\bbu\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=2,\quad \frac{27}{16}\leq q\le ...
- Ui篇--layout_weight体验(实现按比例显示)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...