題意:貪吃蛇的題目
思路:BFS+狀態的記錄,坑了無數發,
#include#include #include using namespace std; const int MAXN = 500000; bool flag[8],vis[25][25],mp[21][21][16384]; int n,m,l; int xx[4]={-1,0,1,0}; // up,right,dow,left int yy[4]={0,1,0,-1}; int front,rear; struct Node { int x,y; int step; int s[8]; int p[8][2]; }; Node q[MAXN]; int _pre(int sx,int sy,int _x,int _y) { int x=_x-sx,y=_y-sy; if(x==-1) return 0; else if(x==1) return 2; else if(y==-1) return 1; return 3; } int adss(Node G) { int va=G.s[0],vb=1,i; for(i=1;i =n || y>=m || vis[x][y]) continue; if(itself(x,y,q[front])) continue; rear=(rear+1)%MAXN; q[rear].x=x,q[rear].y=y,q[rear].step=q[front].step+1; for(int j=0;j