Filthy room P89133


Statement
 

pdf   zip

Professor Filthy Frank has bought a new pet (whose name must remain undisclosed). He wants to prevent it from the horrible fate suffered by his previous hamster Stuart (which didn’t quite differ from that of his previous six pets). In particular, he wants to avoid using his sock to protect it from the cold. Can you find the warmest spot for Frank’s new pet?

Consider a bidimensional infinite world, where the temperature is given by the formula T(x,y)=px+qy+rT(x,y) = px + qy + r. Frank’s room is an nn-sided polygon determined by the intersection of nn half-planes, each one defined by the equation aix+biy+ci0a_i x + b_i y + c_i \ge 0.

Input

Input consist of several cases, each one with nn, pp, qq and rr, followed by nn triples aia_i bib_i cic_i defining the half-planes in any order. (For instance, below you can see the green room of the first sample case.) Assume 3n50003 \le n \le 5000, that at least aia_i or bib_i is non-zero, and that the resulting room has indeed nn sides.

Output

Print the highest temperature inside each room with three digits after the decimal point. The input cases do not have precision issues.

Observation

The expected solution has cost better than Θ(n2)\Theta(n^2).

(10,5)

(0,0)(2,0)(4,2)(3,4)(0,3)

(0,0)(0,5) (0,0)(5,0) (1,0)(1,5) (2,0)(2,5) (3,0)(3,5) (4,0)(4,5) (0,1)(5,1) (0,2)(5,2) (0,3)(5,3) (0,4)(5,4)

Public test cases
  • Input

    5 1.0 0.5 -3.0
    0.0 1.0 0.0
    1.0 -3.0 9.0
    -1.0 1.0 2.0
    1.0 0.0 0.0
    -2.0 -1.0 10.0
    
    4 -1.0 -2.0 -4.0
    1.0 0.0 1.0
    -1.0 0.0 1.0
    0.0 1.0 1.0
    0.0 -1.0 1.0
    
    3 1.23 -4.56 7.89
    42.42 -53.53 64.64
    -98.98 76.76 54.54
    23.23 45.45 10.01
    
    

    Output

    2.000
    -1.000
    9.864
    
  • Information
    Author
    Víctor Martín
    Language
    English
    Official solutions
    C++
    User solutions
    C++