#include #include #include #include #include #define MAX_SIZE 10 #define MAX_STONE 105 using namespace std; class Point{ public: int r, c; Point(){} Point(int r, int c){} bool isAdj(const Point &p) { static int dr[]={0,1,1,0,-1,-1}, dc[]={-1,-1,0,1,1,0}; for(int i=0;i<6;i++) if(r+dr[i]==p.r && c+dc[i]==p.c) return true; return false; } bool operator< (const Point &p) const { if(r==p.r) return c> nBody; if(nBody==0) return false; for(int i=0;i> body[i].r >> body[i].c; cin >> nStone; for(int i=0;i> stone[i].r >> stone[i].c; cin >> goal.r >> goal.c; return true; } bool onStone(Point &p){ for(int i=0;i &next, bool moved, int add){ if(add== 1 && id==nBody) return; if(add==-1 && id==-1) return; const static int dr[]={0,1,1,0,-1,-1}, dc[]={-1,-1,0,1,1,0}; State nextS = curr; nextS.n = curr.n; for(int i=0;i Q; map M; init.n = nBody; for(int i=0;i next; makeNext(0,curr,next,false,1); makeNext(nBody-1,curr,next,false,-1); for(set::iterator i=next.begin();i!=next.end();i++){ if(M.count(*i)==0 || M[*i]>currCost+1){ M[*i] = currCost+1; Q.push(*i); } } } assert(false); } void work(){ cout << bfs() << endl; } int main(){ while(read()) work(); return 0; }