#P3034. [USACO11DEC] Cow Photography G/S
[USACO11DEC] Cow Photography G/S
题目描述
The cows are in a particularly mischievous mood today! All Farmer John wants to do is take a photograph of the cows standing in a line, but they keep moving right before he has a chance to snap the picture.
Specifically, each of FJ's N (1 <= N <= 20,000) cows has a unique integer ID number. FJ wants to take a picture of the cows standing in a line in a very specific ordering, represented by the contents of an array A[1...N], where A[j] gives the ID number of the jth cow in the ordering. He arranges the cows in this order, but just before he can press the button on his camera to snap the picture, a group of zero or more cows (not necessarily a contiguous group) moves to a set of new positions in the lineup. More precisely, a group of zero or more cows steps away from the line, with the remaining cows shifting over to close the resulting gaps in the lineup. The cows who stepped away then re-insert themselves at different positions in the lineup (not necessarily at the locations they originally occupied). Frustrated but not deterred, FJ again arranges his cows according to the ordering in A, but again, right before he can snap a picture, a different group of zero or more cows moves to a set of new positions in the lineup.
The process above repeats for a total of five photographs before FJ gives up. Given the contents of each photograph, see if you can reconstruct the original intended ordering A. Each photograph shows an ordering of the cows that differs from A in that some group of zero or more cows has moved. However, a cow only moves in at most one photograph: if a cow is part of the group that moves in one photograph, she will not actively move in any of the other four photographs (although she could end up at a different index as a consequence of other cows around her moving, of course).
Farmer John居然拍了五张照片,每张表示初始化牛位置的移动后的状态。然后求出FJ这五头牛初始化的样子。
输入格式
* Line 1: The number of cows, N (1 <= N <= 20,000).
* Lines 2..5N+1: The next 5N lines describe five orderings, each one a block of N contiguous lines. Each line contains the ID of a cow, an integer in the range 0...1,000,000,000.
输出格式
* Lines 1..N: The intended ordering A, one ID per line.
题目大意
题目描述
今天的奶牛们特别调皮!Farmer John 想做的只是给排成一排的奶牛拍照,但是在他拍下照片之前,奶牛们一直在移动。
具体地说,FJ 有 头奶牛(),每头奶牛都有一个唯一确定的编号。FJ 想要以一个特定的顺序拍下一张奶牛排成一排的照片,这个顺序用数组 表示,其中 代表排在 位置的奶牛的编号。
他按照这样的顺序将奶牛们排列好,但在他按下快门之前,有些奶牛(可能是零头或任意多头奶牛,位置也不一定连续)将移到一个新的位置。更准确地说,一些奶牛离开队列,剩下的奶牛靠拢,这些离开的奶牛再将自己重新插入到队列中的任意位置(不一定是他们之前的位置)。FJ 感到非常沮丧,他再次按照 数组的顺序重新安排了队列。但在他再次按下快门之前,又有一些奶牛移动到了新的位置。
就这样,FJ 拍了五张照片。给出每张照片拍摄的内容(即 FJ 按下快门时奶牛的顺序),请你尝试推算出 FJ 最初为奶牛们排的顺序(即 数组)。由于可能有奶牛移动,照片显示的顺序与原来的顺序可能有所不同。但是,一头奶牛最多只会移动一次:即如果一头奶牛在拍其中一张照片时移动了,它在拍其他四张照片的时候都不会移动。当然,由于其他奶牛也在移动,它在不同照片中的顺序并不一定相同。
输入格式
第一行包含一个整数 。
接下来 行,每 行描述了一张照片中各奶牛的顺序。每行包含一个奶牛的编号,保证所有编号都是不超过 的非负整数。
输出格式
输出 行,每行一个整数 ,即 FJ 最初为奶牛排好的顺序。
样例解释
FJ 拍的五张照片分别为:
10 20 30 40 50
20 10 30 40 50
30 10 20 40 50
40 10 20 30 50
50 10 20 30 40
5
10
20
30
40
50
20
10
30
40
50
30
10
20
40
50
40
10
20
30
50
50
10
20
30
40
10
20
30
40
50
提示
There are 5 cows, with IDs 10, 20, 30, 40, and 50. In each of the 5 photos, a different cow moves to the front of the line (at most one cow moves in each photo here, but it is possible in other inputs that multiple cows could move in a particular photo).
The correct original ordering A[1..5] is 10, 20, 30, 40, 50.