The 8th Blue Bridge Cup_Question 1_Maze

I feel that the Blue Bridge Cup is getting more and more difficult every year, and the first question this year has been done for a long time.


Title:

A labyrinth playground on Planet Labyrinth X is built on a hillside.
It consists of 10x10 interconnected small rooms.

A large letter was written on the floor of the room.
We assume that the player is standing facing the uphill direction, then:
L means go to the left room,
R means go to the right room,
U means go to the uphill room,
D means go to the downhill room.

The inhabitants of Planet X are a bit lazy and don't want to think hard.
They prefer to play games of luck. So is this game!

At the beginning, the helicopter put 100 players into small rooms.
Players must move according to the letters on the ground.

The map of the maze is as follows:
------------
UDDLUULRUL
UURLLLRRRU
RRUURLDLRD
RUDDDDUUUU
URUDLLRRUU
DURLRLDLRL
ULLURLLRDU
RDLULLRDDD
UUDDUDUDLL
ULRDLUURRR
------------

Please calculate, in the end, how many players will get out Labyrinth?
Instead of going around in circles.

Please submit this integer to indicate the number of players who walked out of the maze, and do not fill in any superfluous content.

If you don't understand the rules of the game, here is a simplified illustration of a 4x4 maze:


Let's take a look at how I did it first. It's a bit stupid, and the C language is not solid. When defining a character array, it is actually written in 100 characters separately. . . Oh my God.

Two-dimensional character array initialization:

char a[3][3] = { {"hyy"},{"zrf"},{"xem"} };

char a[3][3] = { "hyy","zrf","xem" };

Don't be silly to initialize with characters.

#include<stdio.h>

int main(void)
{
	int count = 0;
	char a[10][10] =
	{ {'U', 'D', 'D', 'L', 'U', 'U', 'L', 'R', 'U', 'L'},
	{'U', 'U', 'R', 'L', 'L', 'L', 'R', 'R', 'R', 'U'},
	{'R' ,'R', 'U' ,'U' ,'R' ,'L', 'D' ,'L', 'R', 'D'},
	{'R', 'U' ,'D', 'D' ,'D' ,'D', 'U' ,'U', 'U', 'U'},
	{'U' ,'R', 'U', 'D', 'L', 'L' ,'R' ,'R', 'U', 'U'},
	{'D', 'U', 'R', 'L', 'R', 'L' ,'D', 'L' ,'R', 'L'},
	{'U', 'L', 'L', 'U', 'R' ,'L', 'L', 'R', 'D', 'U'},
	{'R', 'D', 'L' ,'U', 'L', 'L' ,'R', 'D', 'D' ,'D'},
	{'U', 'U', 'D', 'D', 'U' ,'D' ,'U' ,'D', 'L' ,'L'},
	{'U' ,'L', 'R', 'D' ,'L', 'U' ,'U', 'R', 'R' ,'R'} };
	for (int i = 0; i <= 9; i++)
	{
		int time = i;
		for (int j = 0; j <= 9; j++)
		{
			int tempj = j;
			while (1)
			{
				if (a[i][j] == 'U')
				{
					i = i - 1;
					if (i >= 0 && i <= 9 && j >= 0 && j <= 9)
					{
						if (a[i][j] == 'D')
						{
							i = times;
							j = tempj;
							break;
						}
					}
					else
					{
						count++;
						printf("(%d,%d)\n", tempi,tempj);
						i = times;
						j = tempj;
						break;
					}
				}

				if (a[i][j] == 'D')
				{
					i = i + 1;
					if (i >= 0 && i <= 9 && j >= 0 && j <= 9)
					{
						if (a[i][j] == 'U')
						{
							i = times;
							j = tempj;
							break;
						}
					}
					else
					{
						count++;
						printf("(%d,%d)\n", tempi, tempj);
						i = times;
						j = tempj;
						break;
					}
				}

				if (a[i][j] == 'L')
				{
					j = j - 1;
					if (i >= 0 && i <= 9 && j >= 0 && j <= 9)
					{
						if (a[i][j] == 'R')
						{
							i = times;
							j = tempj;
							break;
						}
					}
					else
					{
						count++;
						printf("(%d,%d)\n", tempi, tempj);
						i = times;
						j = tempj;
						break;
					}
				}

				if (a[i][j] == 'R')
				{
					j = j + 1;
					if (i >= 0 && i <= 9 && j >= 0 && j <= 9)
					{
						if (a[i][j] == 'L')
						{
							i = times;
							j = tempj;
							break;
						}
					}
					else
					{
						count++;
						printf("(%d,%d)\n", tempi, tempj);
						i = times;
						j = tempj;
						break;
					}
				}
			}
		}
	}

	printf("%d\n", count);
	return 0;
}
The result is 31. I will see how others write it tomorrow.







Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326015106&siteId=291194637
Recommended