Triangle Counting
Time limit1sMemory limit128 MB
Count how many triangles formed by triples of N integer points strictly contain the origin in their interior.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Two pointers, Combinatorics
- Solved
- No attempts yet
Problem
Bessie is on guard duty, watching the herd from her tower. To pass the time, she imagines the pasture as an plane and studies where the cows are standing.
There are cows (), numbered through . Cow stands at the integer coordinates with . No cow stands on the origin , and the origin never lies on the segment joining any two cows.
Bessie mentally forms every triangle whose three vertices are three different cows. She calls such a triangle golden if it strictly contains the origin in its interior.
Given all of the cow positions, determine how many of these triangles are golden.
Input
- The first line contains one integer .
- Each of the next lines contains two integers and , the coordinates of one cow.
Output
- Print one integer: the number of triangles, formed by three cows, that strictly contain the origin.