Connection Status:
Competition Arena > OrthogonalProjections
TCO19 SRM 754 · 2019-03-25 · by misof · Geometry, Greedy, Math, Sorting
Class Name: OrthogonalProjections
Return Type: int[]
Method Name: generate
Arg Types: (int)
Problem Statement

Problem Statement

If point X lies on the line L, the orthogonal projection of X onto L is X itself. Otherwise, the orthogonal projection of X onto L is the unique point Y on L such that XY is orthogonal to L.

Suppose you are given a finite sequence S of points in the plane. Two lines L1 and L2 are equivalent if the orthogonal projections of points of S onto L1 are in the same order as the projections of points of S onto L2.

For example, suppose the points in S are S[0]=(0,0), S[1]=(0,1), and S[2]=(1,2). The figure below shows two blue lines that are equivalent: the points of S projected onto each of them lie in the order 0, 1, 2.

The second figure below shows the same sequence of points and two other lines. On the red line the projections of 0 and 1 coincide, so the order is 0+1, 2. The green line has the projections in order 1, 0, 2. Thus, these lines represent two new equivalence classes.

(Note that lines don't have direction. A line on which the projections lie in the order 1, 0, 2 is the same as a line on which they are in the order 2, 0, 1.)

For a fixed sequence S of points in the plane let g(S) denote the number of equivalence classes among lines in that plane.

You are given a int n. If there is no S such that g(S) = n, return an empty int[]. Otherwise, find any such S with the following additional properties:

  • S must contain between 1 and 500 points, inclusive.
  • The points in S must be distinct.
  • The coordinates of each point in S must be integers between 0 and 10^9, inclusive.

Then, return the following int[]: { S[0].x, S[0].y, S[1].x, S[1].y, ... }.

Notes

  • For the given constraints, whenever there is a sequence S such that g(S) = n, there is always such a sequence that also satisfies the additional requirements on the length of S and range of values for coordinates.

Constraints

  • n will be between 1 and 100,000, inclusive.
Examples
0)
6
Returns: {0, 0, 0, 1, 1, 2 }

This is the example from the problem statement. We have already shown lines from three equivalence classes. The other three possibilities are listed below. Projections are in order 0, 1+2. Projections are in order 1, 0+2. Projections are in order 0, 2, 1.

1)
47
Returns: { }
2)
8
Returns: {0, 0, 0, 2, 7, 1, 14, 0, 14, 2 }

For the line y = 0 the projections lie in the order 0+1, 2, 3+4. (Note that for example 0+1, 3+4, 2 would have been a different order, but for these five points that order does not correspond to any line in the plane.) For another class of lines the projections lie in the order 1, 0+2+4, 3.

3)
100
Returns: {70, 30, 16, 85, 51, 41, 29, 72, 47, 6, 15, 45, 71, 30, 45, 18, 22, 58, 79, 45, 58, 17 }
4)
1
Returns: {0, 0 }

Submissions are judged against all 81 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OrthogonalProjections with a public method vector<int> generate(int n) · 81 test cases · 2 s / 256 MB per case

Submitting as anonymous