两个DFS()~~~
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char map[10][10];
int xx[4]={0,1,0,-1};
int yy[4]={1,0,-1,0};
struct node
{int x,y;int dir;
};
node res[10000];
void fling(int x,int y,int i)
{int nx=x+xx[i];int ny=y+yy[i];int flag=0;if(nx<0||nx>=7||ny<0||ny>=8){map[x][y]='X';return ;}while(map[nx][ny]=='X'){nx=nx+xx[i];ny=ny+yy[i];if(nx<0||nx>=7||ny<0||ny>=8){flag=1;break;}}if(flag){map[x][y]='X';return ;}map[x][y]='X';map[nx-xx[i]][ny-yy[i]]='O';fling(nx,ny,i);return ;
}
int dfs(int sum,int k)
{if(sum==1){return 1;}char t_map[10][10];memcpy(t_map,map,sizeof(map));int x,y;for(x=0;x<7;x++){for(y=0;y<8;y++){if(map[x][y]=='X')continue;int i;for(i=0;i<4;i++){int nx=x+xx[i];int ny=y+yy[i];if(nx<0||nx>=7||ny<0||ny>=8)continue;if(map[nx][ny]=='O')continue;int flag=0;while(map[nx][ny]=='X'){nx=nx+xx[i];ny=ny+yy[i];if(nx<0||nx>=7||ny<0||ny>=8){flag=1;break;}}if(flag)continue;map[x][y]='X';map[nx-xx[i]][ny-yy[i]]='O';fling(nx,ny,i);res[k].x=x;res[k].y=y;res[k].dir=i;if(dfs(sum-1,k+1))return 1;memcpy(map,t_map,sizeof(t_map));}}}return 0;
}
int main()
{char temp[10];int cas=0;while(scanf("%s",temp)!=EOF){cas++;int i,j;for(i=0;i<8;i++)map[0][i]=temp[i];for(i=1;i<7;i++)scanf("%s",map[i]);int sum=0;for(i=0;i<7;i++){for(j=0;j<8;j++){if(map[i][j]=='O')sum++;}}memset(res,-1,sizeof(res));dfs(sum,0);if(cas!=1)printf("\n");printf("CASE #%d:\n",cas);for(i=0;res[i].dir!=-1;i++){char c;if(res[i].dir==0)c='R';else if(res[i].dir==1)c='D';else if(res[i].dir==2)c='L';else if(res[i].dir==3)c='U';printf("%d %d %c\n",res[i].x,res[i].y,c);}}return 0;
}