CF317E.Princess and Her Shadow
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Princess Vlada enjoys springing in the meadows and walking in the forest. One day — wonderful, sunny day — during her walk Princess found out with astonishment that her shadow was missing! "Blimey!", — she thought and started her search of the shadow in the forest.
Normally the Shadow is too lazy and simply sleeps under the Princess. But at this terrifically hot summer day she got bored of such a dull life, so she decided to play with Vlada.
The forest, where our characters entertain themselves, may be represented as a set of integer cells in the plane, where the Shadow and the Princess can move only up, down, left and right by 1. Some cells (as it happens in decent forests) are occupied by trees. The Shadow and the Princess are not allowed to enter a cell occupied by a tree. Unfortunately, these are the hard times for the forest, so there are very few trees growing here...
At first the Princess was walking within the cell (v__x, v__y), while the Shadow hid from the Princess in the cell (s__x, s__y). The Princess, The Shadow and the trees are located in the different cells.
The Shadow is playing with the Princess. As soon as the Princess moves by 1 in some direction, the Shadow simultaneously flies by 1 in the same direction, if it is possible (if the cell to fly to is not occupied by some tree); otherwise, the Shadow doesn't move. The Shadow is very shadowy, so our characters do not interfere with each other.
We say that the Shadow is caught by the Princess if after some move both of them are located in the same cell. Vlada managed to catch her Shadow! Can you?
公主弗拉达喜欢在草地上跳跃,在森林中漫步。一天——一个美妙、阳光明媚的日子——她在散步时惊讶地发现自己的影子不见了!“天哪!”她心想,随即开始在森林中寻找自己的影子。
通常情况下,影子太懒了,只是简单地躺在公主身下睡觉。但在这个酷热难耐的夏日,它厌倦了如此乏味的生活,于是决定和弗拉达玩个游戏。
我们故事发生的森林可被建模为平面上的一组整数格点,其中影子与公主每次只能向上、下、左、右移动 1 格。某些格点(正如体面的森林中常有的那样)被树木占据;影子与公主均不可进入有树的格点。不幸的是,如今森林正经历艰难时期,因此这里的树木非常稀少……
初始时刻,公主位于格点 (vx,vy),而影子则藏匿于格点 (sx,sy)。公主、影子以及所有树木均位于互不相同的格点上。
影子正在与公主玩耍:每当公主朝某一方向移动 1 格,影子便会同时朝相同方向飞行 1 格(前提是目标格点未被树木占据);否则,影子保持不动。影子极其“影子化”,因此二者互不干扰。
若经过某次移动后,公主与影子处于同一格点,则称影子被公主抓住。弗拉达成功抓住了自己的影子!你也能做到吗?
输入格式
First line of the input contains the coordinates of the characters v__x, v__y, s__x, s__y and the number of trees m (0 ≤ m ≤ 400). The following m lines contain the coordinates of the trees.
All the coordinates are integers between -100 and 100, inclusive. The Princess, The Shadow and the trees are located in the different cells.
输入的第一行包含角色的坐标 vx、vy、sx、sy 以及树的数量 m(0 ≤ m ≤ 400)。接下来的 m 行包含每棵树的坐标。
所有坐标均为介于 −100 到 100(含)之间的整数。公主、影子与各棵树均位于不同的格子中。
输出格式
If it is impossible for the Princess to catch the Shadow, print "-1" (without quotes).
Otherwise print a sequence of characters "L", "R", "D", "U", corresponding to the Princess's moves, following which she will be able to catch the Shadow at some turn (L — move to the left, R — to the right, U — up, D — down; axis x is directed to the right, y — up).
The number of characters (that is, the number of moves) must not exceed 106. All the Princess's moves should be correct, that is must not lead to the cell where a tree grows. It is allowed for the Princess and the Shadow to occupy the same cell before the last turn.
如果公主无法抓住影子,则输出 -1(不带引号)。
否则,输出一串由字符 "L"、"R"、"D"、"U" 组成的序列,表示公主的移动操作,使得她在某一轮中能够抓住影子(L 表示向左移动,R 表示向右移动,U 表示向上移动,D 表示向下移动;其中 x 轴正方向向右,y 轴正方向向上)。
该字符串的长度(即移动步数)不得超过 106。公主的所有移动均须合法,即不能移入长有树木的格子。在最后一轮之前,允许公主与影子处于同一格子。
输入输出样例
输入#1
0 0 1 0 1 0 1
输出#1
LLUR
输入#2
5 0 3 0 8 2 -1 2 0 2 1 3 -1 4 1 4 0 3 1 4 -1
输出#2
-1
输入#3
3 2 1 1 3 0 1 1 0 0 0
输出#3
DLL
说明/提示
Below the pictures for the samples are given (Princess, Shadow and the trees are colored in pink, gray and black correspondingly; the blue dot marks the lattice center).
In the first case the Princess may make two left steps, one step upwards and one right step: 
In the following case the Princess cannot catch the Shadow: 
In the last sample the Princess may make two left steps and one down step (in any order): 
下方给出了样例的示意图(公主、影子和树分别以粉色、灰色和黑色表示;蓝色圆点标记晶格中心)。
在第一种情况下,公主可以向左走两步、向上走一步、再向右走一步:

在接下来的情形中,公主无法抓住影子:

在最后一个样例中,公主可以向左走两步、向下走一步(顺序任意):

输入解题思路,AI测评打分。不知道怎么写?