Find the rational point (X, Y, Z) closest to the origin satisfying N linear inequalities in three variables, or report that none exists.
Hard8GeometryMathBinary searchNo attempts yetTime limit1sMemory limit128 MBThe secret organization K recently built a computer virus so powerful that it can break into any computer in the world. They put the virus on a memory card and locked the card in a safe that opens with a combination of three real numbers X, Y, and Z. The combination is not necessarily unique. Because the virus is very dangerous, organization K does not want every secret agent to know the combination. So each agent received one piece of information, arranged so that no agent can open the safe alone; the safe can be opened only with the information of all the agents together. Each piece of information consists of four integers A, B, C, and D and states that the combination of the safe satisfies
A⋅X+B⋅Y+C⋅Z≤D
Mirko is afraid that organization K could use the virus to destroy the servers of his favorite computer game, where he raises chickens and plants carrots with his neighbor Slavko. He stole the information from all the secret agents of organization K and wants to break into the safe and destroy the virus. There is a problem, though. Mirko does not know how to build the combination of the safe from a list of inequalities.
Help Mirko find a combination (X,Y,Z) that satisfies all the inequalities. If there are several, you must find the one closest to the origin, that is, the one with the smallest X2+Y2+Z2. The set of points satisfying all the inequalities is closed and convex, so whenever a combination exists, exactly one such combination exists.
The first line contains an integer N (1≤N≤100), the number of agents.
Each of the next N lines contains four integers Ai, Bi, Ci, and Di (−1000≤Ai,Bi,Ci,Di≤1000).
Among all real combinations with Ai⋅X+Bi⋅Y+Ci⋅Z≤Di for every i from 1 to N, print the combination (X,Y,Z) with the smallest X2+Y2+Z2 on a single line, separated by spaces.
The coordinates of this combination are always rational, and you must print each one exactly as an irreducible fraction. If a coordinate is an integer, print just that integer (for example 0 or -5). Otherwise print it as p/q, where q≥2, p and q are coprime, and the sign of a negative value goes before p (for example -3/5).
If no combination satisfies all the inequalities, print banana.
In the first example, the known information about the combination of the safe is:
X+Y≤4
Y+2Z≤−3
X≤2
−X≤−1
The combination (1.5,2,−5), for example, also satisfies all the inequalities. However, the combination closest to the origin is (1,−53,−56), where X2+Y2+Z2=514. So the answer is 1 -3/5 -6/5.