Revenge of Collinearity
Time Limit: 8000/5000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 184 accepted submission (s): 51
Problem descriptionin geometry, collinearity is a property of a set of points, specifically, the property of lying on a single line. A set of points with this property is said to be collinear (often misspelled as colinear ).
--- Wikipedia
Today, collinearity takes revenge on you. given a set of N points in two-dimen1_coordinate system, you have to find how many set of <Pi, PJ, PK> from these N points are collinear. note that <Pi, PJ, PK> cannot contains same point, and <Pi, PJ, PK> and <Pi, PK, pj> are considered as the same set, I. e. the order in the Set doesn' t matter.
Inputthe first line contains a single integer T, indicating the number of test cases.
Each test case begins with an integer N, following n lines, each line contains two integers XI and Yi, describing a point.
[Technical Specification]
1. 1 <= T <= 33
2. 3 <= n <= 1 000
3.-1 000 000 000 <= xi, Yi <= 1 000 000 000, and no two points are identical.
4. The ratio of test cases with N> 100 is less than 25%.
Outputfor each query, output the number of three points set which are collinear.
Sample Input
231 12 23 340 01 00 11 1
Sample output
10
Question: Give N points and find the set of points contributed by three points.
Idea: N = 1000. I had no idea when I was playing the game. Although I knew that brute force n ^ 3 would definitely time out, I also handed in what I meant, in normal times, we almost never touch the geometric party ~
After the game, I read the code of a certain God, and the idea was instantly broadened.
Sorts N points by X and Y from small to large. X is the first keyword, and Y is the second keyword.
After sorting out the order, the two-layer for brute-force search is completed. Because the order has been sorted, we can classify all the points with the same slope into a set by slope.
Assume that the current vertex to be determined is I, and P points are collocated with them. Because I must be selected, you only need to select 2 points in the remaining P points, it is p * (PM)/2.
Accumulating these is the answer.
Hdu5020 (determining three-point collinearity) bestcoder round #10 (1003)