Poj 2632 crashing Robots Simulation

Source: Internet
Author: User

question: a rectangle, divided into a * B squares of the same size, set n A robot is placed in some small squares, giving them some instructions. They will step by step follow the instructions, and each time there is only one robot. If two robots are in the same small square, they will collide; if they are out of the border, they will hit the wall. The first collision state of the robot after some commands are output.

# Include <iostream> using namespace STD; int map [101] [101]; int A, B; struct Rob {int X, Y, Sid;} robot [101]; struct instruction {int ro_id, step; char point;} INS [101]; bool proccess (struct Instruction Act) {int I, id = act. ro_id; while (Act. step --) {If (Act. point = 1) robot [ID]. de = (robot [ID]. del + 1) % 4; else if (Act. point =-1) {robot [ID]. del-= 1; if (robot [ID]. del =-1) robot [ID]. de = 3;} el Se if (Act. point = 0) {map [robot [ID]. x] [robot [ID]. y] = 0; Switch (robot [ID]. len) {Case 0: robot [ID]. Y ++; break; Case 1: robot [ID]. X --; break; Case 2: robot [ID]. Y --; break; Case 3: robot [ID]. X ++; break;} If (robot [ID]. Y <1 | robot [ID]. x <1 | robot [ID]. x> A | robot [ID]. y> B) {cout <"robot" <id <"crashes into the wall" <Endl; return false;} else if (Map [robot [ID]. x] [robot [ID]. y]! = 0) {cout <"robot" <id <"crashes into robot" <map [robot [ID]. x] [robot [ID]. y] <Endl; return false;} map [robot [ID]. x] [robot [ID]. y] = ID ;}} return true;} int main () {char ch; int K, n, m; CIN> K; while (k --) {memset (MAP, 0, sizeof (MAP); memset (INS, 0, sizeof (INS); CIN> A> B; cin> N> m; int I; for (I = 1; I <= N; I ++) {CIN> robot [I]. x> robot [I]. y> CH; If (CH = 'n') robot [I]. de = 0; else I F (CH = 'W') robot [I]. del = 1; else if (CH ='s ') robot [I]. del = 2; else if (CH = 'E') robot [I]. DH = 3; Map [robot [I]. x] [robot [I]. y] = I ;}for (I = 1; I <= m; I ++) {CIN> INS [I]. ro_id> CH> INS [I]. step; If (CH = 'l') INS [I]. point = 1; else if (CH = 'R') INS [I]. point =-1; elseins [I]. point = 0 ;}for (I = 1; I <= m; I ++) {If (! Proccess (INS [I]) break;} if (I> m) cout <"OK" <Endl;} return 0 ;}

Related Article

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.