# 2017 AIO(Intermediate) 赛题

## Missing Mango

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.

### Input

The first and only line of input will contain the four non-negative integers IxCxId, and Cd, representing Ishraq's location, Clement's location, Ishraq's distance to the mango, and Clement's distance to the mango, respectively.

### Output

Output should be a single integer, the location of the mango. You should note that this value might be less than zero.

## Tag

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:

• There are N people playing today, and everyone has a different number between 1 and N inclusive.
• At the start of the game, player 1 is on the red team and player 2 is on the blue team. All other players start on no team.
• Over the course of the game, people on a team will tag people who are not on a team. The person who has been tagged then joins the team of the person who tagged them.
• Note that it is possible some of the players will not have been tagged by the end of the game.

As scorer, we need you to figure out how many people are on each team at the end of the game.

### Input

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.

### Output

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.

## Snake Charmer

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:

• An L move: make it turn left and then move forward by one square.
• An R move: make it turn right and then move forward by one square.

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:

1. An R move: it turns right to face east and moves forward one square to the square (1,0).
2. An L move: it turns left to face north and moves forward one square to the square (1,1).
3. An L move: it turns left to face west and moves forward one square to the square (0,1).
4. An R move: it turns right to face north and moves forward one square to the square (0,2).
5. An L move: it turns left to face west and moves forward one square to square (-1,2), which is the goal square where it stops.

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.

### Input

The input file consists of one line with two integers x and y representing the (x,y) coordinates of the goal square.

### Output

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.

## Chimera II

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.

### Input

• The first line of input contains the integer N, the length of DNA sequences.
• The next two lines each contain a string of length N, the two DNA sequences you already have in your laboratory.
• The fourth line contains a string of length N, the required hybrid sequence.

Each string in the input consists only of upper case letters.

It is guaranteed that all three strings in the input will be different.

### Output

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.