NOIP 2013 提高组 华容道

准备用A*算法, 和 IDA*算法分别试一下。


A*算法

最好的A*算法 详解

摘自:https://www.redblobgames.com/pathfinding/a-star/introduction.html

国人翻译:https://www.cnblogs.com/L-Arikes/p/4314113.html 

在摘录一篇

http://blog.csdn.net/hitwhylz/article/details/23089415





 IDA*算法


分支定界其实是A*算法的雏形

迭代加深搜索(IDDFS )其实也是 ID A*的雏形

https://wenku.baidu.com/view/9dc0e27002768e9951e738d5.html


还没有写得完的华容道。

#include <iostream>

#include <bits/stdc++.h>
using namespace std;
const int MM=200001;
int  chess[30][30];
int N,M,Q;
int dx={0,0,0,1,-1};
int dy={0,-1,1,0,0}

struct Node{

      int d;  //初始状态到此状态的距离
      int h;  //此状态到目标状态的距离
      //int status; //棋盘状态 30行,30列,存不下啊!!

      int X_space, Y_space; //当前空白位置。
      int x, y; //当前在x。y位置。

       bool operator <(  Node b) const{     //原来这里必须加const
            return ( d + h > b.d + b.h);
      }

};

void request(int Ex,int Ey,int Sx,int Sy, int Tx, int Ty){
      priority_queue< Node > que;
      que.push( (Node){ 0, MM ,Ex, Ey, Sx, Sy} );
      while( !que.empty()){
            Node v = que.front(); que.pop();
            for(int i=1;i<=4;i++){
                  int newx, newy;
                  newx += dx[i]; newy += dy[i];
                  //曼哈顿距离棋子偏离目标位置的水平距离和垂直距离和
                  if(  ) que.push()
                  
            } 
            
      }
}

int main()
{
    cin >> N >> M >> Q;

    memset( chess, 0 , sizeof(chess));
    for(int i=0;i<N;i++)
      for(int j=0;j<M;j++){
         int a; cin>>a;
         //if(a==1) {  S = S | (1<<(i*M+j) ;} //棋盘状态 30行,30列,存不下啊!!
         chess[i][j] = a;
      }

    for(int i=1;i<=Q;i++){
      int ex,ey,sx,sy,tx,ty;
      cin>>ex>>ey>>sx>>sy>>tx>>ty;
      request(ex,ey,sx,sy,tx,ty);
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值