P177 test 6-4 UVa439
//P177 test 6-4 UVa439
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
, , , , -, -, -, -}; //转向控制
, -, , -, , -, , -};
][]; //记录步数
void bfs(int x,int y,int ex,int ey)
{
queue<int> a, b;
a.push(x);
b.push(y);
int px, py;
;
while(!a.empty())
{
px = a.front();
a.pop();
py = b.front();
b.pop();
; i < ; i++)
{
&& px + turnx[i] <= && py + turny[i] > && py + turny[i] <= )
{
step[px + turnx[i]][py + turny[i]] = step[px][py] + ;
b.push(py + turny[i]);
a.push(px + turnx[i]);
if(px + turnx[i] == ex && py + turny[i] == ey)
{
kase = ;
break;
}
}
}
if(kase)break;
}
}
int main()
{
int x, ex, y, ey;
],s2[];
)
{
x = s1[] - ;
y = s1[] - ' ;
ex = s2[] - ;
ey = s2[] - ' ;
memset(step, , sizeof(step));
bfs(x,y,ex,ey);
printf("%d\n", step[ex][ey]);
}
;
}
P177 test 6-4 UVa439的更多相关文章
- P177 test 6-3 UVa536
//P177 test 6-3 #include<cstdio> #include<cstring> using namespace std; +],s2[+]; int re ...
- [刷题]算法竞赛入门经典(第2版) 6-4/UVa439 6-5/UVa1600
比较忙比较累,只贴代码了. 题目:6-4 UVa439 - Knight Moves //UVa439 - Knight Moves //Accepted 0.000s //#define _XIEN ...
- uva-439
题意:骑士在一个8*8的棋盘上移动,1-8代表行号,a-h代表列号,给出骑士的初始位置和目的位置,求骑士最少的移动步数:题目隐含一层意思(骑士移动规则是中国象棋的“马”的走法) 输入:一串字符串,包含 ...
- uva439 - Knight Moves(BFS求最短路)
题意:8*8国际象棋棋盘,求马从起点到终点的最少步数. 编写时犯的错误:1.结构体内没构造.2.bfs函数里返回条件误写成起点.3.主函数里取行标时未注意书中的图. #include<iostr ...
- UVa439——骑士的移动
简单bfs #include <iostream> #include <cstring> #include <string> #include <map> ...
- Uva439:BFS题目总结
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstring> #include <cstd ...
- UVA439 knightMoves (A*启发搜索)
第一个A*,纪念下. A*要保证最短路一定要估价函数小于等于实际值,越接近越好 估价函数取Manhattan距离除以二. //Rey #include<cstdio> #include&l ...
- 【习题 6-4 UVA-439】Knight Moves
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] bfs模板题 [代码] /* 1.Shoud it use long long ? 2.Have you ever test sev ...
- UVA439 骑士的移动 Knight Moves
#include<bits/stdc++.h> using namespace std; char a,c; int b,d; ][]; ]={,,,-,,-,-,-}; ]={,-,,, ...
随机推荐
- HTML 表单元素之 input 元素
介绍HTML 5: 表单元素之 input 元素 表单元素之 input 元素 - text, password, url, telephone, email, search, file, radio ...
- C#常用网址
C# 编程指南 https://msdn.microsoft.com/zh-cn/library/67ef8sbd.aspx
- javascript中的字典
1.概念 字典是一种以键值对的形式存储的数据结构,就系那个电话本中的名字和电话号码一样.要找到一个电话首先要找到名字,再根据名字找到电话号码.这里的键就是指用来查找的东西,值就是查找得到的结果. Ja ...
- bzoj1562[NOI2009]变换序列——2016——3——12
任意门:http://www.lydsy.com/JudgeOnline/problem.php?id=1562 题目: 对于0,1,…,N-1的N个整数,给定一个距离序列D0,D1,…,DN-1,定 ...
- UVa 10720 - Graph Construction
题目大意:给n个整数, 分别代表图中n个顶点的度,判断是否能构成一张图. 看到这个题后,除了所有数之和应该为偶数之外,没有别的想法了,只好在网上搜解题报告了.然后了解了Havel-Hakimi定理.之 ...
- 05 Linux字符驱动---静态注册
1. mycdev.c #include <linux/init.h> #include <linux/module.h> #include <linux/cdev.h& ...
- loading.io一个loading图标网站,跟大家分享
loading.io是官方网址在首页选一款loading图标,看到左上角的 Try it now中有选中的图标后,可通过光标滑动选择图标大小,然后再点右边的get svg或get css等下载即可
- Java打印
Java打印 import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Gra ...
- Core Audio 在Vista/Win7上实现
应用范围:Vista / win7, 不支持XP 1. 关于Windows Core Auido APIs 在Windowss Vista及Windows 7操作系统下,微软为应用程序提供了一套新的音 ...
- 2017了,回家前 "年末" 分享:下雨,飘雪,红包雨,碰撞球,自定义View
(本博客为原创:http://www.cnblogs.com/linguanh/) 目录: 效果展示 感想 代码拆解 开源地址 效果展示 有没有兴趣继续看下去,直接看下"颜值"是第 ...