嗯,长见识~~
收藏起来,慢慢研究。
我当年写的那个树的结构比较烂,只能线性查。
听老杨说他的那个能 O(1) 的查,感觉挺神奇。
[ 本帖最后由 pangding 于 2012-3-7 22:49 编辑 ]

收藏起来,慢慢研究。
我当年写的那个树的结构比较烂,只能线性查。
听老杨说他的那个能 O(1) 的查,感觉挺神奇。
[ 本帖最后由 pangding 于 2012-3-7 22:49 编辑 ]

2012-03-07 22:45

2012-03-07 23:26

2012-03-07 23:51
2012-03-08 11:52
2012-03-08 12:16
2012-03-08 12:19

2012-03-08 14:53
程序代码:
int CLaoYangWnd::kangtuo(char a[])
{
int fac[]={1,1,2,6,24,120,720,5040,40320};//康托展开判重
int i,j,sum = 0,t = 0;
for(i = 0;i<9;i++)
{
t = 0;
for(j = i+1;j<9;j++)
if(a[j]<a[i])
t++;
sum += t*fac[9-i-1];
}
return sum+1;
}
void CLaoYangWnd::bfs()
{
char h[4] = {'d','u','r','l'};
int i,x,y;
Node now,next;now.pa = "";next.pa = "";
for(i = 0;i<8;i++)now.a[i] = i+1;
now.a[8] = 0;now.pos = 8;
now.index = 46234;foot[46234] = true;
queue<Node> q;q.push(now);
int dec[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
while(!q.empty())
{
now = q.front();
q.pop();
for(i = 0;i<4;i++)
{
x = now.pos/3+dec[i][0];
y = now.pos%3+dec[i][1];
if(x<0 || y<0 || x>2 || y>2)
continue;
next = now;
next.pos = 3*x+y;
next.a[next.pos] = 0;
next.a[now.pos] = now.a[next.pos];
next.index = kangtuo(next.a);
if(!foot[next.index])
{
foot[next.index] = true;
next.pa += h[i];
path[next.index] = next.pa;
q.push(next);
}
}
}
}
2012-03-08 17:18
2012-03-10 17:26
2012-03-10 17:43