// 广度遍历----连连看.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 ;
广度优先遍历的应用
最新推荐文章于 2023-09-21 06:00:00 发布