/**<  */#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的更多相关文章

  1. poj 1651 http://poj.org/problem?id=1651

      http://poj.org/problem?id=1651Multiplication Puzzle   Time Limit: 1000MS   Memory Limit: 65536K To ...

  2. 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 ...

  3. 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 ...

  4. POJ3278http://poj.org/problem?id=3278

    http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...

  5. OpenJudge/Poj 1207 The 3n + 1 problem

    1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

  6. POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)

    http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...

  7. poj 1681 Painter&#39;s Problem(高斯消元)

    id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...

  8. POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!

    水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...

  9. <挑战程序设计竞赛> poj 3320 Jessica's Reading Problem 双指针

    地址 http://poj.org/problem?id=3320 解答 使用双指针 在指针范围内是否达到要求 若不足要求则从右进行拓展  若满足要求则从左缩减区域 代码如下  正确性调整了几次 然后 ...

随机推荐

  1. BZOJ 2844 albus就是要第一个出场(高斯消元)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2844 题意: 给出一个长度为n的正整数数列A.每次选出A的一个子集进行抑或(空集抑或值为 ...

  2. MyBatis学习总结3-优化MyBatis配置文件

    连接数据库配置优化 可以将数据库连接配置信息卸载conf.xml中,但是为了优化连接,专门写一个properties用于存数据库连接信息,然后在conf.xml中进行引用,里面包括数据库驱动,地址,用 ...

  3. 转载:C++ STL set学习

    声明:本文转载自Penguin的博客 http://blog.sina.com.cn/s/blog_779cf3410101389s.html 1,set的含义是集合,它是一个有序的容器,里面的元素都 ...

  4. bzoj2085

    首先看到k的范围就该知道这题不是倍增就是矩乘 首先肯定要求出任意一对串(a,b) a的后缀与b的前缀相同的最长长度是多少 考虑到kmp求出的失配指针是一个串最长后缀和前缀相等的长度 这里多个串我们只要 ...

  5. 使用Jquery promise 动态引入js文件

    动态加载一个js得方式很多,如下方式: /** *一般方式加载 */ function normalLoadScript(url) { var node = document.createElemen ...

  6. SQL Server索引怎么用

    什么是索引 拿汉语字典的目录页(索引)打比方:正如汉语字典中的汉字按页存放一样,SQL Server中的数据记录也是按页存放的,每页容量一般为4K .为了加快查找的速度,汉语字(词)典一般都有按拼音. ...

  7. 出现错误ActivityManager: Warning: Activity not started, its current task has been

    1.在学习两个Activity的切换时,重新把新的工程部署上模拟器时候出现错误:ActivityManager: Warning: Activity not started, its current ...

  8. 【转】零基础写Java知乎爬虫之进阶篇

    转自:脚本之家 说到爬虫,使用Java本身自带的URLConnection可以实现一些基本的抓取页面的功能,但是对于一些比较高级的功能,比如重定向的处理,HTML标记的去除,仅仅使用URLConnec ...

  9. BrowserSync,调试利器--自动刷新(转

    ---恢复内容开始--- 请想象这样一个场面:你开着两个显示器,一边是IDE里的代码,另一边是浏览器里的你正在开发的应用.此时桌上还放着你的手机,手机里也是这个开发中的应用.然后,你新写了一小段代码, ...

  10. javascript 命名空间的实例应用

    /** * 创建全局对象MYAPP * @module MYAPP * @title MYAPP Global */ var MYAPP = MYAPP || {}; /** * 返回指定的命名空间, ...