"Hdoj" 1813 Escape from Tetris

Source: Internet
Author: User

The minimum distance from the pretreatment of BFS to the boundary is ida* to find out the feasible scheme. Note Initialize the dir array by dictionary order. And there is an intermediate point of 1, with a 0 probability of the boundary (WA many times). No commands are output at this time.

1 /*1813*/2#include <iostream>3#include <queue>4#include <algorithm>5#include <cstdio>6#include <cstring>7#include <cstdlib>8 using namespacestd;9 Ten #defineMAXN 80 One #defineINF 0XFFFFFF A  - intN, M; - Charmp1[4][6] = { the     "East", -     " North", -     " South", -     "West" + }; - intop[1005]; + intX[MAXN], Y[MAXN]; A intdis[9][9]; at intvisit[9][9]; - Charmap[9][9]; - intdir[4][2] = { -     0,1,-1,0,1,0,0,-1 - }; -  inInlineBOOLIsend (intXinty) { -     returnx==0|| x==n-1|| y==0|| y==n-1; to } +  -InlineBOOLCheckintXinty) { the     returnx<0|| X>=n | | y<0|| y>=N; * } $ Panax Notoginseng intBFsintXinty) { -     intxx, yy; the     intI, J, K; +queue<int>Q; A      theK =Ten*x +y; + Q.push (k); -memset (Visit,-1,sizeof(visit)); $Visit[x][y] =0; $      -      while(!Q.empty ()) { -K =Q.front (); the Q.pop (); -x = k/Ten;Wuyiy = k%Ten; the          for(i=0; i<4; ++i) { -xx = x + dir[i][0]; Wuyy = y + dir[i][1]; -             if(map[xx][yy]=='1'|| visit[xx][yy]>=0) About                 Continue; $VISIT[XX][YY] = visit[x][y]+1; -             if(Isend (xx, yy)) -                 returnVisit[xx][yy]; -K =Ten*xx +yy; A Q.push (k); +         } the     } -     return 0; $ } the  the BOOLDfsintDint*PX,int*py) { the     intMmax =-1; the     intX[MAXN], Y[MAXN]; -     intI, J, K; in      the      for(i=0; i<m; ++i) theMmax =Max (Mmax, Dis[px[i]][py[i]); About     if(Mmax >d) the         return false; the     if(d = =0) the         return true; +      -      for(i=0; i<4; ++i) { theOP[D] =i;Bayi          for(j=0; j<m; ++j) { theX[J] = Px[j] + dir[i][0]; theY[J] = Py[j] + dir[i][1]; -             if(Isend (Px[j], py[j]) | | map[x[j]][y[j]]=='1') { -X[J] =Px[j]; theY[J] =Py[j]; the             } the         } the         if(Dfs (d1, x, y)) -             return true; the     } the     return false; the }94  the intMain () { the     intt =0; the     intI, J, K;98      About #ifndef Online_judge -Freopen ("data.in","R", stdin);101Freopen ("Data.out","W", stdout);102     #endif103     104      while(SCANF ("%d", &n)! =EOF) { them =0;106          for(i=0; i<n; ++i)107scanf"%s", Map[i]);108          for(i=0; i<n; ++i) {109              for(j=0; j<n; ++j) { the                 if(Map[i][j] = ='1') {111DIS[I][J] =INF; the}Else {113                     if(Isend (i, J)) { theDIS[I][J] =0; the}Else { theDIS[I][J] =BFS (i, j);117X[M] =i;118Y[M] =J;119++m; -                     }121                 }122             }123         }124         if(t++) theprintf"\ n");126         if(m) {127              for(i=1; ; ++i) { -                 if(Dfs (i, x, y))129                      Break; the             }131              for(J=i; j>0; --j) theprintf"%s\n", Ops[op[j]]);133         }134     }135     136     return 0;137}

"Hdoj" 1813 Escape from Tetris

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.