p0j-1835-Astronaut-Simulation (1)

Source: Internet
Author: User

Astronauts
Time Limit: 2000MS Memory Limit: 30000K
Total Submissions: 4866 Accepted: 2077

Description

Problem Description:
Astronauts lost their way in space, in his starting position now create a virtual xyz coordinate system, called the absolute coordinate system, the astronaut's positive direction is the positive x-axis direction, the head direction is the z-axis positive direction, the astronaut's initial state as shown:

Six directions are respectively labeled, X, Y, z positive direction respectively is 0,1,2, negative direction is 3,4,5; they are called absolute directions. Astronauts only walk in the universe in a direction parallel to the XYZ axis of the absolute coordinate system, but he does not know his current absolute coordinates and the absolute direction of his face.

Task Description:
Determine the ultimate absolute coordinates and the absolute orientation of the astronauts according to the astronauts ' description of their movements in the opposite direction. The description and meaning of moving in the relative direction are as follows:
Forward x go forward x m.
Back x Turn first, then walk x m.
Left x go first, then x M.
Right x first turn to starboard and then x M.
Up X face up first, then x M.
Down x face down first, then x meters.
Where up and down as shown:

Input

The first line is a positive integer m, which represents the number of groups of test data. The first row of each set of test data is a positive integer n (1<=n<=10000) representing the number of times the astronaut walks, and the following n lines enter one relative walk per line, in the format described above, where (1 <= x <= 10000 is a positive integer).

Output

For each set of input data output a row, x y z p, the middle is separated by a space, x y z is the absolute coordinates of the astronaut's position, p is the astronaut oriented absolute direction number (0<=p <=5).

Sample Input

16left 10right 11up 12down 13forward 14back 15

Sample Output

23-10 12 3

Source

[email protected]


Idea: First show the initial state, positive = 0, left = 4, above = 2, with the change of coordinates, the relative relations of the three faces also follow the change
#include <stdio.h>intMain () {intN,i; scanf ("%d",&N);  while(n--)    {        Charstr[ One]; intFace=0, left=4, head=2, temp,x=0, y=0, z=0, D,m; scanf ("%d",&m);  for(i=0; i<m;i++) {scanf ("%s%d",str,&d); if(str[0]=='b') { face= (face+3)%6;//plus 3 is the opposite direction in this direction for the 6 to take the remainder. Left= (left+3)%6; }             Else if(str[0]=='L') {Temp=Face ; face=Left ; Left= (temp+3)%6; }             Else if(str[0]=='R') {Temp=Left ; Left=Face ; face= (temp+3)%6; }             Else if(str[0]=='u') {Temp=Face ; face=Head; Head= (temp+3)%6; }             Else if(str[0]=='D') {Temp=Head; Head=Face ; face= (temp+3)%6; }             if(face==0) x+=D; if(face==1) y+=D; if(face==2) Z+=D; if(face==3) x-=D; if(face==4) y-=D; if(face==5) Z-=D; } printf ("%d %d%d%d\n", X,y,z,face); }}

p0j-1835-Astronaut-Simulation (1)

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.