Directional Resemblance
Time limit10sMemory limit128 MB
Find the pair with the smallest nonzero angle among up to 120000 3D vectors per dataset, where some vectors come from a given pseudorandom generator.
Problem
Every vector has a direction, and two vectors determine one angle between them. Given a set of three-dimensional vectors, find the pair among them that makes the smallest angle.
Input
The input is a sequence of datasets. One dataset specifies one set of three-dimensional vectors. Some of the vectors are written in the dataset directly and the rest are produced by the procedure below.
Each dataset has the following format.
m n S W
x1 y1 z1
x2 y2 z2
.
.
.
xm ym zm
The first line has four integers , , , and .
is the number of vectors whose three components are written in the dataset directly. The next lines hold those components, and the -th of them means the vector . Every vector component is a positive integer at most .
is the number of vectors produced by the following procedure.
int g = S;
for (int i = m + 1; i <= m + n; i++) {
x[i] = (g / 7) % 100 + 1;
y[i] = (g / 700) % 100 + 1;
z[i] = (g / 70000) % 100 + 1;
if (g % 2 == 0) { g = (g / 2); }
else { g = (g / 2) ^ W; }
}
For , the three components of the -th vector of the set are the values , , and that this procedure computes.
and are the values given on the first line of the dataset, and , .
The total number of vectors satisfies . The same vector may be specified twice or more in a single dataset.
A line containing four zeros indicates the end of the input. The total of over all datasets in the input never exceeds .
Output
For each dataset, print on one line the two vectors of the given set whose angle is the smallest among all nonzero angles. At least two vectors have different directions.
A vector is written by its three components. Print a pair of vectors and in this format.
xa ya za xb yb zb
Two vectors and compare in dictionary order, that is, if , or if and , or if , and . When you print a pair, print the smaller vector in this order first.
If more than one pair makes the equal smallest angle, print the pair that is the smallest among them in the dictionary order between vector pairs. The pair is smaller than the pair if , or if and .