Counting ear shapes
Time limit2sMemory limit512 MB
Count quadruples of red points and pairs of blue points forming an ear shape with angle and containment conditions.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force, Sorting, Implementation
- Solved
- No attempts yet
Problem
The coordinate plane holds red points and blue points. Every red point has coordinate , and every blue point has a coordinate greater than .
Subin wants to build an ear shape out of these points. An ear shape is made of four distinct red points , , , and two distinct blue points , , and it must satisfy all three conditions below.
- Point and point lie in the interior of segment .
- Angle , angle , angle and angle are all smaller than degrees.
- Point lies in the interior of triangle . It must not lie on a side.
Given the red points and the blue points, write a program that counts the ways to build an ear shape.
Swapping with , or with , gives the same ear shape. Two ear shapes count as different when they differ in the two points used as and , the two points used as and , the point , or the point .
Input
The first line contains and . ()
The second line contains the coordinates of the red points.
Each of the next lines contains the coordinate and the coordinate of one blue point.
Every coordinate in the input is a natural number no greater than . The red points are distinct, and the blue points are distinct.
Output
Print the number of ways to build an ear shape on the first line.
Hint
Suppose the red points sit at , , , , and the blue points are , , , . All four red points are used, so and are the points at and , and and are the points at and . There are four ways to pick and .
- ,
- ,
- ,
- ,