Poj 2632 crashing robots

Source: Internet
Author: User

Crashing robots
Time limit:1000 ms   Memory limit:65536 K
Total submissions:7505   Accepted:3279

Description

In a modernized warehouse, robots are used to fetch the goods. careful planning is needed to ensure that the robots reach their destinations without crashing into each other. of course, all warehouses are rectangular, and all robots occupy a circular floor space with a diameter of 1 meter. assume there are n robots, numbered from 1 through N. you will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. instructions are processed in the order they come. no two robots move simultaneously; a robot always completes its move before the next one starts moving.
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.

Input

The first line of input is K, the number of test cases. each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the ew-direction, and B in the NS-direction.
The second line contains two integers, 1 <= n, m <= 100, denoting the numbers of robots and Instructions respectively.
Then follow n lines with two integers, 1 <= xi <= A, 1 <= Yi <= B and one letter (N, S, E or W ), giving the starting position and direction of each robot, in order from 1 through N. no two robots start at the same position.

Figure 1: The starting positions of the robots in the sample warehouse
Finally there are m lines, giving the instructions in sequential order.
An instruction has the following format:
<Robot #> <action> <repeat>
Where is one
  • L: Turn left 90 degrees,
  • R: Turn right 90 degrees, or
  • F: move forward one meter,

And 1 <= <repeat> <= 100 is the number of times the robot shocould perform this single move.

Output

Output one line for each test case:
  • Robot I crashes into the wall, if robot I crashes into a wall. (A robot crashes into a wall if xi = 0, xi = a + 1, YI = 0 or YI = B + 1 .)
  • Robot I crashes into robot J, if robots I and j crash, and I is the moving robot.
  • OK, if no crashing occurs.

Only the first crash is to be reported.

Sample Input

45 42 21 1 E5 4 W1 F 72 F 75 42 41 1 E5 4 W1 F 32 F 11 L 11 F 35 42 21 1 E5 4 W1 L 961 F 25 42 31 1 E5 4 W1 F 41 L 11 F 20

Sample output

Robot 1 crashes into the wallRobot 1 crashes into robot 2OKRobot 1 crashes into robot 2

I hate simulated questions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!


The AC code is as follows:


# Include <iostream> # include <cstring> # include <cstdio> using namespace STD; struct H {int H, Z; char F;} RT [105]; int T; int n, m, G, s; int X [105], Y [105]; int map [105] [105]; char f [105] [105]; char d [105] [2]; char B; int A, C; int BJ; void DS () // turn to {C = C % 4; if (B = 'R') // the left and right sides are symmetric c = 4-C; If (C = 1) {If (RT [A]. F = 'n') rt [A]. F = 'W'; else if (RT [A]. F = 'E') rt [A]. F = 'n'; else if (RT [A]. F ='s ') rt [A]. F = 'E'; else if (RT [A]. F = 'W') rt [A]. F ='s ';} else if (C = 2) {If (RT [A]. F = 'n') rt [A]. F ='s '; else if (RT [A]. F = 'E') rt [A]. F = 'W'; else if (RT [A]. F ='s ') rt [A]. F = 'n'; else if (RT [A]. F = 'W') rt [A]. F = 'E';} else if (C = 3) {If (RT [A]. F = 'n') rt [A]. F = 'E'; else if (RT [A]. F = 'E') rt [A]. F ='s '; else if (RT [A]. F ='s ') rt [A]. F = 'W'; else if (RT [A]. F = 'W') rt [A]. F = 'n' ;}} void DF () // forward function {int I; If (RT [A]. F = 'W') {int xx = RT [A]. z-C; for (I = RT [A]. z-1; I> = xx; I- -) If (Map [RT [A]. H] [I]! = 0 & I> = 1) {printf ("Robot % d crashes into robot % d \ n", A, map [RT [A]. h] [I]); bj = 1; break;} If (XX <1 & bj = 0) {printf ("Robot % d crashes into the wall \ n", a); bj = 1;} If (bj = 0) {map [RT [A]. h] [RT [A]. z] = 0; Map [RT [A]. h] [XX] = A; RT [A]. z = XX ;}} else if (RT [A]. F = 'n') {int xx = RT [A]. H + C; for (I = RT [A]. H + 1; I <= xx; I ++) if (Map [I] [RT [A]. z]! = 0 & I <= N) {printf ("Robot % d crashes into robot % d \ n", A, map [I] [RT [A]. z]); bj = 1; break;} If (XX> N & bj = 0) {printf ("Robot % d crashes into the wall \ n ", a); bj = 1;} If (bj = 0) {map [RT [A]. h] [RT [A]. z] = 0; Map [XX] [RT [A]. z] = A; RT [A]. H = XX ;}} else if (RT [A]. F = 'E') {int xx = RT [A]. Z + C; for (I = RT [A]. Z + 1; I <= xx; I ++) if (Map [RT [A]. h] [I]! = 0 & I <= m) {printf ("Robot % d crashes into robot % d \ n", A, map [RT [A]. h] [I]); bj = 1; break;} If (XX> M & bj = 0) {printf ("Robot % d crashes into the wall \ n", a); bj = 1;} If (bj = 0) {map [RT [A]. h] [RT [A]. z] = 0; Map [RT [A]. h] [XX] = A; RT [A]. z = XX ;}} else if (RT [A]. F ='s ') {int xx = RT [A]. h-C; for (I = RT [A]. h-1; I> = xx; I --) if (Map [I] [RT [A]. z]! = 0 & I> = 1) {printf ("Robot % d crashes into robot % d \ n", A, map [I] [RT [A]. z]); bj = 1; break;} If (XX <1 & bj = 0) {printf ("Robot % d crashes into the wall \ n ", a); bj = 1;} If (bj = 0) {map [RT [A]. h] [RT [A]. z] = 0; Map [XX] [RT [A]. z] = A; RT [A]. H = XX ;}}int main () {int I, j; CIN >>t; while (t --) {bj = 0; memset (MAP, 0, sizeof map); memset (F, 0, sizeof F); CIN> m> N> G> S; for (I = 1; I <= g; I ++) {CIN> Y [I]> X [I]> d [I] [0]; map [x [I] [Y [I] = I; RT [I]. H = x [I]; RT [I]. z = Y [I]; RT [I]. F = d [I] [0]; F [x [I] [Y [I] = d [I] [0]; // cout <map [x [I] [Y [I] <F [x [I] [Y [I] <Endl ;} for (I = 1; I <= s; I ++) {CIN> A> B> C; If (bj = 1) continue; if (B = 'l') DS (); else if (B = 'R') DS (); else if (B = 'F ') DF (); // cout <A <"" <RT [A]. h <"" <RT [A]. z <"" <RT [A]. F <Endl;} If (bj = 0) cout <"OK" <Endl;} return 0 ;}


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.