[Blue Bridge Cup] previous questions ranton ant, Blue Bridge previous questions ranton

Source: Internet
Author: User

[Blue Bridge Cup] previous questions ranton ant, Blue Bridge previous questions ranton
Previous questions ranton antTime Limit: 1.0 s memory limit: 256.0 MBProblem description

Langton ant, proposed by Chris Langton in 1986, is a type of cellular automation.

The square lattice on the plane is filled in black or white. There is an ant in one square ".
The head orientation of the ant financial system is: either of the top, bottom, and left.

Ant financial's mobile rules are very simple:
If the ant is in the black box, turn right for 90 degrees, change the box to the white box, and move the Grid forward;
If the ant is in the White grid, turn left for 90 degrees, change the grid to the Black Grid, and move the Grid forward.

Although the rules are simple, ant financial's behavior is very complicated. The routes left at the beginning are always symmetric, as if they are repeated. However, no matter what the initial status is, after a long and chaotic activity, ant financial will open up a regular "highway ".

The routes of ant financial are hard to predict in advance.

Your task is to use a computer to simulate the location of the ranton ant after the nth walk.Input FormatThe first line of the input data is the integer m n (3 <m, n <100), indicating the number of rows and columns in the square lattice.
Next is m rows of data.
Each row contains n numbers separated by spaces. 0 indicates the white space, and 1 indicates the black space.

Next is a row of data: x y s k, where x y is an integer, indicating the row number and column number of the ant financial. (The row number increases from top to bottom, and the column number increases from left to right, are numbered from 0 ). S is an uppercase letter that indicates the orientation of the ant's head. We agree that the upper, lower, and lower sides are represented by: UDLR respectively. K indicates the number of steps taken by ANT Financial.Output FormatThe output data is an integer p q separated by two spaces, indicating the row number and column number of the grid in which the ant financial is located after k steps.Sample Input5 6
0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
2 3 L 5Sample output1 3Sample Input3 3
0 0 0
1 1 1
1 1 1
1 1 U 6Sample output0 0Java source code:

1 import java. util. optional; 2 3 public class Main {4 5 public static void main (String [] args) {6 char [] lz = {'l', 'D', 'R ', 'U'}; // array of 7 char [] rz = {'l', 'U', 'R', 'D '}; // array 8 9 records in = new records (System. in); 10 int n = in. nextInt (); 11 int m = in. nextInt (); 12 13 int [] [] maps = new int [n] [m]; 14 for (int I = 0; I <n; I ++) 15 for (int j = 0; j <m; j ++) 16 maps [I] [j] = in. nextInt (); 17 18 int x = in. nextInt (); 19 int y = in. nextInt (); 20 char s = in. next (). trim (). charAt (0); 21 int k = in. nextInt (); 22 23 for (int j = 0, I = 0; j <k; j ++) {24 if (maps [x] [y] = 1) {// Black Grid turn right 90 degrees 25 maps [x] [y] = 0; // set to white grid 26 for (I = 0; I <4; I ++) 27 if (rz [I] = s) 28 break; 29 s = rz [(I + 1) % 4]; 30 switch (s) {31 case 'l ': 32 y --; 33 break; 34 case 'r': 35 y ++; 36 break; 37 case 'U': 38 x --; 39 break; 40 case 'D ': 41 x ++; 42 break; 43} 44} else {// left turn on the white lattice 90 degrees 45 maps [x] [y] = 1; // set it to a Black Grid 46 for (I = 0; I <4; I ++) 47 if (lz [I] = s) 48 break; 49 s = lz [(I + 1) % 4]; 50 switch (s) {51 case 'l': 52 y --; 53 break; 54 case 'r ': 55 y ++; 56 break; 57 case 'U': 58 x --; 59 break; 60 case 'D': 61 x ++; 62 break; 63} 64} 65} 66 System. out. println (x + "" + y); 67} 68}

 

Evaluation point No. Evaluation Result Score CPU usage Memory usage Download evaluation data
1 Correct 33.33 218 ms 23.66 MB Input and Output
2 Correct 33.33 156 ms 23.41 MB Input and Output
3 Correct 33.33 124 ms 23.63 MB Input and Output
 

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.