Blue Bridge Cup Langton Ant (analogue)

Source: Internet
Author: User

Previous questions Langton ant time limit: 1.0s memory limit: 256.0MBProblem description

Langton Ant, which was introduced by Chris Langton in 1986, belongs to a kind of cellular automata.

The square lattice on the plane is filled with black or white. There is an "ant" in one of the squares.
The head of the ant is facing: up and down on one side.

The rules for moving ants are very simple:
If the ant is in Haig, turn right 90 degrees, change the lattice to white, and move forward one cell;
If the ant is in white, turn left 90 degrees, change the grid to black, and move forward one cell.

Although the rules are simple, the behavior of ants is very complex. The route left at the beginning will be nearly symmetrical, like repeating, but no matter what the starting state is, the ants will open up a regular "freeway" after a lengthy chaotic activity.

The ant's route is difficult to predict beforehand.

Your task is to use a computer to simulate the position of the Langton Ant after the nth Walk, based on the initial state. Input format the first line of input data is m n two integers (3 < m, n < 100), representing the number of rows and columns of the square lattice.
Next is the M-row data.
Each row of data is n a number separated by a space. 0 means white and 1 for Haig.

Next is a row of data: x y S K, where x y is an integer, which indicates the ant's line number and column number (row numbers grow from top to bottom, column numbers grow from left to right, and are numbered starting with 0). S is a capital letter, indicating the head of the ant, we agreed: up and down respectively with: Udlr said. K indicates the number of steps the ant walks. Output format output data is two spaces separated by the integer p Q, respectively, the ant after the K-step, the row and column number of the lattice. Sample Input 5 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 5 Sample Output 1 3 example input 3 3
0 0 0
1 1 1
1 1 1
1 1 U 6 sample output 0 0 just want to be weak and say a code that writes is really lame, but after a forget AC code
#include <stdio.h> #include <string.h>int map[1010][1010];int sx,sy,dir;void fun (int sign) {if (dir==1) {if ( sign) {dir=4;sy++;} else{dir=3;sy--;}} ElseIf (dir==2) {if (sign) {dir=3;sy--;} else{dir=4;sy++;}} ElseIf (dir==3) {if (sign) {dir=1;sx--;} else{dir=2;sx++;}} ElseIf (dir==4) {if (sign) {dir=2;sx++;} else{dir=1;sx--;}}} int main () {int n,m;while (scanf ("%d%d", &n,&m)!=eof) {int I,j,k;char c;for (i=0;i<n;i++) {for (j=0;j<m;j++ ) scanf ("%d", &map[i][j]);} scanf ("%d%d%c%d", &sx,&sy,&c,&k), if (c== ' U ') dir=1;elseif (c== ' d ') dir=2;elseif (c== ' L ') dir=3;elseif (c== ' R ') dir=4;while (k--) {int px=sx;int py=sy;fun (Map[sx][sy]), if (map[px][py]) map[px][py]=0;elsemap[px][py]=1;} printf ("%d%d\n", Sx,sy);}}


Blue Bridge Cup Langton Ant (analogue)

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.