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 解答 使用双指针 在指针范围内是否达到要求 若不足要求则从右进行拓展 若满足要求则从左缩减区域 代码如下 正确性调整了几次 然后 ...
随机推荐
- ubuntu10.04开启root登陆
半年没有用ubuntu了,以前用的是8.10,现在装了一个10.04,第一印象就是登陆窗口变了,哎,比较喜欢用root用户登录系统,不喜欢非root用户,做任何事都要来一下sudo,10.04的登陆窗 ...
- 查看EBS中BI Publisher的版本
查看EBS中BI Publisher的版本问题,Oracle提供了如下的几种方法: 从BI Publisher产生的报表文件查看 通过系统已打过的补丁(Patch)来决定,通过补丁号和BI Publi ...
- HDU 3492 (直线与所有线段相交) Segment
题意: 给出n个线段,判断是否存在一条直线使得所有线段在直线上的射影的交非空. 分析: 如果我们找到一条与所有线段相交的直线,然后做一条与该直线垂直的直线,这些线段在直线上的射影就一定包含这个垂足. ...
- kendo grid输入框验证方法
$("#grid").kendoGrid({ dataSource: dataSrc, //toolbar: ["save", "取消"], ...
- LeetCode: Word Break I && II
I title: https://leetcode.com/problems/word-break/ Given a string s and a dictionary of words dict, ...
- 【流媒體】live555—VS2010 下live555编译、使用及测试
Ⅰ live555简介 Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现了对多种音视频编 ...
- 【大数处理、正则表达式】NYOJ-513
[正则] 正则表达式是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为“元字符”). 模式描述在搜索文本时要匹配的一个或多个字符串. 常用字符: //正则表达式 //$ 匹配 ...
- Android 获取本机WIFI及3G网络IP
获取本机WIFIprivate String getLocalIpAddress() { WifiManager wifiManager = (WifiManager) getSystemServic ...
- 指针和引用的比较(P105)
指针和引用的比较? 虽然使用引用和指针都可间接访问另一个值,但它们之间有两个重要区别. 第一个区别在于引用总是指向某个对象:定义引用时没有初始化是错误的. 第二个重要区别则是赋值行为的差异:给引用赋值 ...
- qt 设置背景图片
博客出处:http://www.cppblog.com/qianqian/archive/2010/07/25/121238.htm 工作似乎走上正轨了,上周五的工作是做一个界面,用到QFrame和Q ...