已知若干个城市的地图,求从一个城市到另一个城市的路径,要求路径中经过的城市最少。

#include<iostream>
#include<cstring>
using namespace std;
int ju[][]=
{{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,}};
int a[],b[],s[],head,tail;
void print(int d)
{
cout << char(a[d]+);
while(b[d]){
d=b[d];
cout << "--" << char(a[d]+);
}
cout << endl;
}
void bfs()
{
int i;
head=;tail=; //tail依次记录每个节点
a[]=;b[]=;s[]=; //a数组记录每个节点上城市,b数组记录上一个城市的节点,s记录走过的城市
do{
head++;
for(i=;i<=;i++){
if(ju[a[head]][i]== && s[i]==){
tail++;
a[tail]=i;
b[tail]=head;
s[i]=;
if(i==) {
print(tail);
return;
}
}
}
}while(head<tail);
}
int main()
{
memset(s,,sizeof(s));
bfs();
return ;
}

最新文章

  1. JDK安装,环境配置
  2. ipad横竖屏尺寸(转载)
  3. Android系统onKeyDown监控/拦截/监听/屏蔽返回键、菜单键和Home键
  4. (转) C++ static、const和static const 以及它们的初始化
  5. centos 安装http协议的git server
  6. 启语外语培训网SEO历程
  7. Oracle表空间、段、区和块
  8. 【转】MAC使用adb工具
  9. VB6.0连接MySQL数据库
  10. python混账的编码问题解决之道
  11. httpappplication 和 httpmodule 的理解(转载,写的很好)
  12. QPixmap 在非QtCreator环境下无法显示jpg图片
  13. Java Networking: UDP DatagramSocket (翻译)
  14. PHP中使用Elasticsearch
  15. 【CSS】元素样式
  16. jqgrid 使用自带的行编辑
  17. [BZOJ1135][POI2009]Lyz[霍尔定理+线段树]
  18. PLSQL Developer windows 64位连接数据库的问题
  19. 软工1816 &#183; Beta冲刺(2/7)
  20. flex版本问题总结

热门文章

  1. adb install INSTALL_FAILED_ALREADY_EXISTS
  2. 移动端视网膜(Retina)屏幕下1px边框线 解决方案
  3. ORACLE_UNQNAME
  4. HTTP的客户端识别与cookie机制
  5. angularJS绑定数据时自动转义html标签
  6. PHP 验证码生成类(可定制长度和内容)
  7. python模块引用问题(比较杂乱,懒得整理)
  8. git+github上传与管理
  9. Intent
  10. MySQL interval()函数