Test instructions
A maze, people start in the exit position, asked to traverse a maze, back to the initial position, now give a plan to walk, to draw out the maze
People start facing to the right
F: Take a step forward
R: Turn right and take a step forward
L: Turn left and take a step forward
B: Turn back and take a step forward
Ideas:
Direct simulation can
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <math.h> #include <bitset># Include <algorithm> #include <climits>using namespace std; #define LS 2*i#define rs 2*i+1#define up (i,x,y) for (i=x;i<=y;i++) #define DOWN (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __gcd (A, b) #define LL long long#define ULL unsigned long long#define N 100005#define INF 0x3f3f3f3f#define EXP 1e-8#define rank rank1const int mod = 1000000007;int T,len;char str[1000000];int to[4][2]={0,1,1,0,0,-1,-1,0},vis[30 0][300];int Main () {int i,j,k; scanf ("%d", &t); printf ("%d\n", t); while (t--) {MEM (vis,0); scanf ("%s", str); len = strlen (str); int r = 0; int x = 128,y=128; Vis[x][y] = 1; int maxx,maxy,minx,miny; Maxx = Maxy = Minx = MIny = 128; for (i = 0;i<len;i++) {if (str[i]== ' F ') {x+=to[r][0]; Y+=TO[R][1]; Vis[x][y] = 1; } else if (str[i]== ' R ') {r = (r+1)%4; X+=TO[R][0]; Y+=TO[R][1]; Vis[x][y] = 1; } else if (str[i]== ' B ') {r = (r+2)%4; X+=TO[R][0]; Y+=TO[R][1]; Vis[x][y] = 1; } else if (str[i]== ' L ') {r = (r+3)%4; X+=TO[R][0]; Y+=TO[R][1]; Vis[x][y] = 1; } Maxx = max (maxx,x); Maxy = max (maxy,y); Minx = min (minx,x); miny = min (miny,y); } printf ("%d%d\n", maxx-minx+3,maxy-miny+2); for (i = minx-1;i<=maxx+1;i++) {for (j = miny;j<=maxy+1;j++) { if (Vis[i][j]) printf ("."); else printf ("#"); } printf ("\ n"); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
BAPC2014 J&&hunnu11590:jury Jeopardy