其他分享
首页 > 其他分享> > 八结点(广搜)

八结点(广搜)

作者:互联网

#include<bits/stdc++.h>
using namespace std;
int ju[9][9]={{0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,1,0,1,1},
{0,0,1,1,1,1,0,1,1},
{0,0,1,1,0,0,1,1,1},
{0,0,1,0,1,1,1,0,1},
{0,1,1,0,1,1,1,0,0},
{0,0,0,1,1,1,1,1,0},
{0,1,1,1,0,0,1,1,0},
{0,1,1,1,1,0,0,0,1}};
int a[101],b[101];
bool s[9];
void out(int d)
{
cout<<char(a[d]+64);
while(b[d])
{
d=b[d];
cout<<"--"<<char(a[d]+64);
}
}
void bjd()
{
int head=0,tail=1;
a[1]=1;
b[1]=0;
do
{
head++;
for(int i=1;i<=8;i++)
{
if(!(ju[head][i])&&!s[i])
{
tail++;
s[i]=1;
a[tail]=i;
b[tail]=head;
if(i==8)
{
out(tail);
head=tail;
break;
}

}
}
}while(head<tail);
}
int main()
{
bjd();
return 0;
}

标签:结点,bjd,cout,int,ju,head,tail
来源: https://www.cnblogs.com/yingboyoyo/p/14643166.html