Time Limit: 1 second
Memory Limit: 1 GB
Input File: manin.txt
Output File: manout.txt
Ishraq and Clement have lost their mango and need help finding it again! Ishraq and Clement are standing on a straight line. Their positions are denoted by a single integer specifying how far they are from the left-hand end of the line. The mango is also on the line, but its exact location is unknown. Both Ishraq and Clement know how far away from the mango they are, but they don't know what direction the mango is in. Given the location of Ishraq and Clement, and their respective distances to the mango, determine the location of the mango. It is guaranteed that there will always be a single possible location for the mango.
The first and only line of input will contain the four non-negative integers Ix, Cx, Id, and Cd, representing Ishraq's location, Clement's location, Ishraq's distance to the mango, and Clement's distance to the mango, respectively.
Output should be a single integer, the location of the mango. You should note that this value might be less than zero.
Time Limit: 1 second
Memory Limit: 1 GB
Input File: tagin.txt
Output File: tagout.txt
Thank you for being the scorer for our game of tag. The rules are pretty simple:
As scorer, we need you to figure out how many people are on each team at the end of the game.
The first line of input will contain two integers N and M: the number of players in the game and the number of tags that occur during the game, respectively. M lines will follow, describing the tags that happen in chronological order. Each line will contain two integers a and b. This indicates that player a tags player b, so now player b joins player a's team. It is guaranteed that, prior to this tag, player a is already on a team and player b is not.
Your program must output two integers on one line. The number of players on the red team at the end of the match, and the number of players on the blue team at the end of the match.
Input File: snakein.txt
Output File: snakeout.txt
Time Limit: 1 second
Memory Limit: 1 GB
You are a snake charmer performing for a travelling circus troupe. For your next act, you will show off your skills by charming your snake to move to a place selected by an audience member. To perform this act, you have created a grid for your snake to move around in. Initially your snake starts off in a square in the middle of this grid facing north, and you will ask the audience for a goal square for your snake to reach. However, your snake is very peculiar: it only likes to move by zigzagging around. More specifically you can only make your snake move in two ways:
For instance, consider the following grid in a coordinate system.
Your snake will always start off at the square (0,0). In the above grid, the flag square at (-1,2) represents the goal square selected by the audience, and the dots show the path taken. The snake is initially facing north, so the sequence of moves taken by it are:
Now, you realise that the longer it takes for your snake to get to the goal square, the less interested your audience will become. Can you find the shortest path for you to charm your snake to the goal square? If there are multiple shortest paths, you only need to find one of them.
The input file consists of one line with two integers x and y representing the (x,y) coordinates of the goal square.
Your output file should consist of a single line of Ls and Rs, representing a sequence of moves that will charm your snake from the starting point to the goal square.
Input File: chimin.txt
Output File: chimout.txt
Time Limit: 1 second
Memory Limit: 1 GB
You've just graduated from high school and are ready to start your very own mad science lab. To prove your genius to the world you plan to breed a lion-goat hybrid.
All animals in existence are fundamentally described by their DNA sequence, which is a string of N upper case letters. You've managed to obtain the DNA sequences of a lion and of a goat. To bring your new creature to life, you must produce a specific DNA sequence, called the hybrid sequence.
New DNA sequences can be produced by splicing. This involves picking two DNA sequences from your lab (call these sequences S and T) and an integer x (0 < x < N), called the splicing point. Your state-of-the-art DNA photocopier will then produce a new DNA sequence which consists of the first x characters of S, followed by the last N-x characters of T. This new sequence is then stored in your lab and can be used for future splicing.
For example, say you pick the DNA sequences GOLEM and MOOSE, and take x=2. The splicing will take GO from the start of GOLEM and OSE from the end of MOOSE, and combine these to get the new DNA sequence GOOSE.
There's been a wave of blackouts recently, so to conserve power you want to minimise use of the DNA photocopier. Determine if it is possible to create the hybrid sequence, and if so the minimum number of splices required.
Each string in the input consists only of upper case letters.
It is guaranteed that all three strings in the input will be different.
If it is impossible to produce the hybrid sequence, your program should output PLAN FOILED. Otherwise, your problem should output two lines. On the first line you should output SUCCESS, and on the second line you should output a single integer: the minimum number of times you must splice to produce the required sequence.
© 2024. All Rights Reserved. 沪ICP备2023009024号-1