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; ][]; ]={,,,-,,-,-,-}; ]={,-,,, ...
随机推荐
- PHPEXCEL实例-导出EXCEL
PHPExcel 是相当强大的 MS Office Excel 文档生成类库,当需要输出比较复杂格式数据的时候,PHPExcel 是个不错的选择. <?php /* * 导出EXCEL * ...
- vs2015编译mysql c++ connector
目前MySQL Connector/C++的binary版本最高只支持VS2008,VS2015需要下载源码自行编译. 1.CMAKE 到官网下载最新的稳定版本 把bin目录添加到环境变量PATH中 ...
- zabbix3.0.4 部署History
[root@zabbix-Test ~]# history 1 passwd root 2 exit 3 yum install ntpd* 4 yum inst ...
- Samba匿名用戶仅仅唯读访问
NAS(Network Attached Storage),网络附加存储需要支持NFS(Network File System)和CIFS(Common Internet File Sysem)一 ...
- 2.5. Integer 16 、Integer 32、Integer 64(Core Data 应用程序实践指南)
Core Data 使用 “带符号的整数”,通常我们会选择Integer 32,如果不够,可以升级为Integer 64 (第3章),通过升级托管对象模型. 这三种类型对应的特性(Property)类 ...
- 建立、配置和使用Activity——启动其他Activity并返回结果
Activity还提供了一个startActivityForResult(Intent intent,int requestCode)方法来启动其他Activity.该方法用于启动指定Activity ...
- 【Zookeeper】源码分析之Watcher机制(三)之Zookeeper
一.前言 前面已经分析了Watcher机制中的大多数类,本篇对于ZKWatchManager的外部类Zookeeper进行分析. 二.Zookeeper源码分析 2.1 类的内部类 Zookeeper ...
- 微信小程序开发系列(二)小程序的全局文件
其实你已经知道了小程序的文件结构 上一节讲到,小程序的页面由三部分组成: 视图(.wxml).逻辑(.js).样式(.wxss). 我们这次重新展开文件结构: 小程序用到的文件类型只有四种,正如你所看 ...
- CodeForces758D
D. Ability To Convert time limit per test:1 second memory limit per test:256 megabytes input:standar ...
- 实现过程全纪录——自己写一个“微信朋友圈”(包括移动端与PC端)
一.朋友圈的基本单元--动态 首先定义一个自定义控件用来显示每条动态. 二.运行效果 三.核心解读 PushedMessage 有个PushIndex属性,表示发送消息的index,从0开始递增.每个 ...