Tmdtmd
Ida* didn't run away. What is ida*?
is an iterative deep search +a* estimate price.
But why was the day adjusted?
n<=2 when I output something ....
Watched the day.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#defineMAXN 15#defineINF 2000000000using namespacestd;intn,map[maxn][maxn],tot=0, dis[maxn][maxn],mx=0, ans[maxn*maxn*MAXN],D,DR[MAXN][MAXN];intdx[]={0,0,-1,1,0},dy[]={0,1,0,0,-1};CharS[maxn];queue<int>Q;structpoint{intx, y; Point (intXinty): x (x), Y (y) {} point () {}}P[MAXN*MAXN];BOOLBndintXinty) { if((x==1) || (x==n) | | (y==1) || (y==n))return true; return false;}BOOLJudgeintXinty) { if((x>=1) && (x<=n) && (y>=1) && (y<=n))return true; return false;}intBFsintXinty) { for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) Dr[i][j]=inf; while(!q.empty ()) Q.pop (); Dr[x][y]=0; Q.push (x); Q.push (y); while(!Q.empty ()) { intHx,hy; HX=q.front (); Q.pop (); hy=Q.front (); Q.pop (); if(BND (Hx,hy))returnDr[hx][hy]; for(intI=1; i<=4; i++) { inttx=hx+dx[i],ty=hy+Dy[i]; if((Map[tx][ty]) && (dr[tx][ty]==inf) &&(judge (Tx,ty))) {Q.push (TX); Q.push (Ty); Dr[tx][ty]=dr[hx][hy]+1; } } } returninf;}intGets_h (Point p[]) {intmx=0; for(intI=1; i<=tot;i++) mx=Max (mx,dis[p[i].x][p[i].y]); returnMX;} Point Modify (point x,inty) { if(BND (X.X,X.Y))returnx; Point now=point (x.x+dx[y],x.y+Dy[y]); if((!map[now.x][now.y]) | | (!judge (NOW.X,NOW.Y)))returnx; Else returnNow ;}BOOLIDA (intDeep,point p[]) {Point NODE[MAXN*MAXN]; if(Gets_h (p) +deep>d)return false; if(Deep==d)return true; for(intI=1; i<=4; i++) {Ans[deep]=i; for(intj=1; j<=tot;j++) node[j]=Modify (P[j],i); if(IDA (deep+1, node))return true; } return false;}voidWork () {tot=0; Memset (ans,0,sizeof(ans)); for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) Dis[i][j]=-1; for(intI=1; i<=n;i++) {scanf ("%s", s); for(intj=1; j<=n;j++) { if(s[j-1]=='0') map[i][j]=1; Elsemap[i][j]=0; if((Map[i][j]) && (!BND (i,j)) p[++tot]=Point (I,J); } } if(!tot)return; for(intI=1; i<=n;i++) for(intj=1; j<=n;j++) { if(!map[i][j]) dis[i][j]=inf; Else { if(BND (I,J)) dis[i][j]=0; Elsedis[i][j]=BFS (I,J); MX=Max (mx,dis[i][j]); if(Dis[i][j]==inf) {printf ("cx_naive\n");return;} } } for(d=1;; d++) { if(IDA (0, p)) { for(intj=0; j<d;j++) { if(ans[j]==1) printf ("east\n"); Else if(ans[j]==2) printf ("north\n"); Else if(ans[j]==3) printf ("south\n"); Else if(ans[j]==4) printf ("west\n"); } return; } }}intMain () {intret=0; while(SCANF ("%d", &n)! =EOF) { if(ret++) printf ("\ n"); Work (); } return 0; }
HDU 1813 Escape from Tetris