当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1148:Utopia Divided

Special Judge 特殊评判
题目描述
The beautiful land of Utopia was once ravaged by war. When the hostilities subsided the country was divided into four regions by a longitude (north-south line) and a latitude (east-west line). The intersection of these lines became known as the point (0,0). All four parts claimed the name Utopia, but as time went by they generally became known as Utopia 1 (northeast), 2 (northwest), 3 (southwest) and 4 (southeast). A point in any of the regions was identified by its distance east and its distance north of (0,0). These distances could be negative; hence a point in Utopia 2 was designated by a (negative, positive) pair, in Utopia 3 by a (negative, negative) pair, in Utopia 4 by (positive, negative) and in Utopia 1 by a pair of positive numbers.

A major problem was that citizens were not permitted to cross borders. Fortunately, some ingenious IOI contestants from Utopia developed a safe means of teleportation. The machine requires code numbers, each of which can only be used once. Now the challenge facing the team, and you, is to guide the teleporter from its initial position of (0,0) to the regions of Utopia in the order requested. You don抰 care where in a region you land, but you will have a sequence of N region numbers that specify the regions in which the teleporter is to land. You may be asked to land in the same region in two or more consecutive stops. After leaving the initial (0,0) point, you must never land on a border.

You will receive as input a sequence of 2N code numbers and are to write them as a sequence of N code pairs, placing a plus or a minus sign before each number. If you are currently at the point (x,y) and use the code pair (+u,-v), you will be teleported to the point (x+u, y-v). You have the 2N numbers, and you can use them in any order you like, each with a plus or a minus sign.

Suppose you have code numbers 7, 5, 6, 1, 3, 2, 4, 8 and are to guide the teleporter according to the sequence of region numbers 4, 1, 2 ,1. The sequence of code pairs (+7,-1), (-5,+2), (-4,+3), (+8,+6) achieves this as it teleports you from (0,0) to the locations (7,-1), (2,1), (-2,4) and (6,10) in that order. These points are located in Utopia 4, Utopia 1, Utopia 2, and Utopia 1, respectively.
TASK
You are given 2N distinct code numbers and a sequence of N region numbers indicating where the teleporter is to land. Construct a sequence of code pairs from the given numbers that guide the teleporter to go through the given region sequence.
输入解释
Your program is to read from standard input. The first line contains a positive integer N (1 <= N <= 10000). The second line contains the 2N distinct integer code numbers (1 <= code number <= 100000) separated by single spaces. The last line contains a sequence of N region numbers, each of which is 1, 2, 3 or 4.
输出解释
Your program is to write to standard output. The output consists of N lines, each containing a pair of code numbers each preceded by a sign character. These are codes pairs that will direct the teleporter to the given region sequence. Note that there must be no blank following a sign, but there must be a single space after the first code number.

If there are several solutions your program can output any one of them. If there are no solutions your program should output the single integer 0.
输入样例
4
7 5 6 1 3 2 4 8
4 1 2 1
输出样例
+7 -1
-5 +2
-4 +3
+8 +6

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 IOI 2002

源链接: POJ-1148

最后修改于 2020-10-29T05:54:04+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000