UVa 118-mutant Flatworld Explorers

Source: Internet
Author: User

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

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.