Title: give you a n*m lattice, now there are a lot of robots (given initial coordinates and orientation) to walk on it, ask the final position and orientation,
If you go to the border it will drop and mark the point before the drop, so that the robot behind it does not go this way.
Analysis: Simulation. Direct simulation can be used to calculate the adjacent direction using the cyclic take-off, using the map to mark the points not to go.
Note: Notice that the skipped point is the point on the map, before some of the robot passed here and fell down, he walked here will also fall down on the jump.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int maps[55][55];int dxy[4][2] = {0,1,1,0,0,-1,-1,0};int main () { int N,m,x,xx,y,yy,towards[128];char start,steps[105],face[5] = "NESW"; towards[' n '] = 0;towards[' E '] = 1;towards[' S '] = 2 ; towards[' W '] = 3;memset (maps, 0, sizeof), scanf ("%d%d", &n,&m), while (~SCANF ("%d%d%c", &x,&y, &start) {scanf ("%s", steps), int face_now = Towards[start],flag = 0;for (int i = 0; steps[i]; + + i) {if (steps[i] = = ' L ') Face_now = (face_now+3)%4;if (steps[i] = = ' R ') Face_now = (face_now+1)%4;if (steps[i] = = ' F ') {xx = X+dxy[face_now][0];yy = y+dxy[face_now][1];if (xx < 0 | | xx > N | | yy < 0 | | yy > m) {if (Maps[x][y]) continue;maps[x][y] = 1;flag = 1;break;} x = Xx;y = yy;}} printf ("%d-%c", X,y,face[face_now]), if (flag) printf ("LOST");p rintf ("\ n");} return 0;}
UVa 118-mutant Flatworld Explorers