hdu3004 The Chess

一道广搜题。。用六维hash判重即可,要注意一下马的别脚和炮的隔山打牛。。。稍微细心点敲就应该不会错。。。随后附上部分有针对性的生成数据,仅供参考(答案自己去算)

附代码如下

# include 
# include 
using namespace std;
const int size = 11;
struct node
{
       int mx, my;
       int px, py;
       int cx, cy;
       int step; 
};
int n, m;
int sx, sy;
bool hash[size][size][size][size][size][size];
node start, next, pre;
const int GoM[8][2] = {{1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}};
const int GoM1[8][2] = {{0, 1}, {0, -1}, {0, 1}, {0, -1}, {1, 0}, {1, 0}, {-1, 0}, {-1, 0}};
const int GoC[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char mapp[size][size];
int ans;
bool check(int x, int y)
{
     return (x >= 0 && x < n && y >= 0 && y < m);     
}
/*void pri(node a)
{
     for (int i = 0; i < n; i ++){
         for (int j = 0; j < m; j ++){
             if (i == a.mx && j == a.my)cout<<"M";
             else
             if (i == a.cx && j == a.cy)cout<<"C";
             else
             if (i == a.px && j == a.py)cout<<"P";
             else if (mapp[i][j] == 'D')cout<<"D";
             else if (mapp[i][j] == 'S')cout<<"S";
             else cout<<'.';
         }    
         cout< Que;
     Que.push(start);
     hash[start.mx][start.my][start.px][start.py][start.cx][start.cy] = true;
     while (!Que.empty()){
           node pre = Que.front();
           Que.pop();
           //pri(pre);
           //cout< 2 )break;//
                  
                  //cout<<"flag:"<


 

 

你可能感兴趣的:(搜索,include,struct,c)