#P1302. Visible Squares from the Origin
Visible Squares from the Origin
Visible Squares from the Origin
We are given n non‐overlapping squares on the plane. The vertices of each square have integer coordinates. Let \(O(0,0)\) be the coordinate origin. A square \(R\) is said to be visible from \(O\) if and only if one can select two distinct points \(A\) and \(B\) on the boundary of \(R\) such that the interior of the triangle \(\triangle OAB\) (i.e. the set of points that can be expressed as a convex combination of \(O\), \(A\), and \(B\) with all coefficients strictly positive) has no common points with any of the other squares. Given the n non-overlapping squares, compute the number of squares that are visible from \(O\).
The mathematical condition can be expressed as follows: for a candidate square \(R\), if there exist two distinct points \(A, B \in \partial R\) such that \[ \big\{x\mid x=\lambda O+(1-\lambda)[\mu A+(1-\mu)B], \; \lambda,\mu\in (0,1)\big\} \] does not intersect any other square, then \(R\) is visible from \(O\).
Note: The squares are axis‐aligned (their sides are parallel to the axes) and do not overlap (their common area is zero, though they may touch along edges or vertices).
inputFormat
The first line contains an integer n representing the number of squares. Each of the following n lines contains four integers: x1 y1 x2 y2
, representing two opposite vertices of an axis‐aligned square. You may assume that for each square, after ordering the coordinates, the square covers the region \([x_{min}, x_{max}]\times[y_{min}, y_{max}]\).
outputFormat
Output a single integer: the number of squares visible from the origin \(O(0,0)\).
sample
1
1 1 2 2
1
</p>