广度优先遍历的应用

// 广度遍历----连连看.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <queue>
using namespace std;
#define UNBOUND 1234

/**
author:songzhengchao
time:2013/10/19
funtion:连连看程序,找出从一个位置(x1,y1)到(x2,y2)的最小转弯下
的条件下,最小的距离
转弯小于3次
用广度遍历,这里以转弯的次数作为距离了



*******/
struct node 
{
	int x;
	int y;
	int low;//从(x,y)到源点的最小转弯数
	int cost;//从(x,y)到源点的最小转弯数的条件下,移动的步数
	node(int a=0,int b=0):x(b),y(b){};
	struct node* pre;
};
/*假设连连画如下,C[i][j]=1 表示i,j有图片  =0表示没有图片*/
int C[4][4]={
	{0,0,0,0},
	{0,1,0,0},
	{0,0,1,0},
	{0,0,0,0},

};
int visited[4][4]={0};


int _tmain(int argc, _TCHAR* argv[])
{
	node nodearr[4][4];
	queue<node >Q;
	//初始化
	int i,j;
	for(i=0;i<4;i++)
		for(j=0;j<4;j++)
		{
			nodearr[i][j].x=i;
			nodearr[i][j].y=j;
			nodearr[i][j].pre=NULL;
			nodearr[i][j].cost=UNBOUND ;
			
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值