讨论 / ORZ
飞雪天涯 2008-11-14 06:39:00
点我顶贴 收藏 删除
叔叔不移动“将”???
#1 飞雪天涯@2008-11-14 04:51:00
回复 删除
那是和棋!
#2 飞雪天涯@2008-11-14 06:39:00
回复 删除
#include<iostream>

using namespace std;

struct pointset{

int x,y;

int father;

};

pointset bfs[1000];

bool visited[100][100];

int dir[8][2]={

{1,2},

{2,1},

{-1,2},

{-2,1},

{1,-2},

{2,-1},

{-1,-2},

{-2,-1}

};

bool check(int x,int y){

if (x<1||x>10) return false;

if (y<1||y>9) return false;

if (x==1&&y==4) return false;

if (x==1&&y==6) return false;

if (x==2&&y==5) return false;

return true;

}

int main (void){

memset(visited,false,sizeof(visited));

int open,closed;

open=closed=0;

cin>>bfs[open].x>>bfs[open].y;

bfs[open].father=-1;

closed++;

while (open<closed){

int x,y;

x=bfs[open].x;

y=bfs[open].y;

visited[x][y]=true;

for (int i=0;i<8;i++){

int xi,yi;

xi=x+dir[i][0];

yi=y+dir[i][1];

if (check(xi,yi)&&!visited[xi][yi]){

bfs[closed].x=xi;

bfs[closed].y=yi;

bfs[closed].father=open;

if (xi==1&&yi==5){

int p=open,count=0;

while (p!=-1){

count++;

p=bfs[p].father;

}

cout<<count;

goto extd;

}

closed++;

}

}

open++;

}

cout<<"No Answer";

extd:

//while (1);

return 0;

}

/*

2 2

----

2

*/

查看更多回复
提交回复