#P7081. [NWRRC 2013] Correcting Curiosity
[NWRRC 2013] Correcting Curiosity
题目描述
Curiosity is the rover that explores the Gale Crater on Mars. Recently it found an evidence of water in Martian soil, which will make it easier to plan the future manned missions.
Curiosity can communicate with Earth directly at speeds up to , but on average minutes and seconds will be required for signals to travel between Earth and Mars.
You have just seen a stone and applied brakes, but you know that the rover is already passing that stone -- Matt Heverly, the rover's driver, explains. So we just plan the route, then write down a list of simple textual commands: move one meter ahead, turn left, make a photo and so on.
Sometimes it is necessary to react very fast to some unexpected events. For example, if the cameras have seen something interesting, then you might want to change the route of the rover to make an additional photo. To do that, you send a substitution command of the form . This replaces all occurrences of starting with the leftmost one, to
More formally, if A is a non-empty string and is a string, then to apply the substitution command to a string , you should do the following:
Find the leftmost occurrence of A in , such that SL A SR.
If there is no such occurrence, stop. Then, is the answer.
Let be the result of applying to SR.
The answer is SL .
This means that:
If there are two overlapping occurrences of A in , only the leftmost one is replaced. For example, applying to abababa yields cbc: after replacing the first occurrence of aba the string turns to cbaba, and only the last occurrence of aba can be replaced after that.
No substitution uses the results of previous substitutions. For example, applying to a yields ab, applying to a yields ba.
You know that the longer is the command, the bigger is the time necessary to transmit it. So, you have to write a program that finds shortest command that transforms the initial string to the final string.
输入格式
The first line contains the initial and the final strings. Both strings are non-empty and their lengths do not exceed characters. The strings contain only English letters, spaces and punctuation signs (commas, colons, semicolons and hyphens: The given strings are not equal.
输出格式
Output the substitution command that transforms initial string to final string and has the minimum length. If there are several shortest substitution commands, output any of them.
move left, move right; move up
move left, move down, move up
s/right;/down,/g
If not found: move x; else move -x
If found: move x; else move -x
s/ not//g
abababa
cbc
s/aba/c/g
提示
Time limit: 2 s, Memory limit: 256 MB.