Description
Farmer John has recently invented a game to test the pretentious Bessie. At the beginning of the game, FJ would give Bessie a piece of wood with a non-coincident point of N (2 <= n <= 200), where the horizontal and vertical coordinates of the point I were x_i and y_i ( -1,000 <= x_i <=1,000; -1,000 <= y_i <= 1,000). Bessie could choose two dots to draw a straight line over them, and only if there were no straight lines parallel to the drawing line in the plane. At the end of the game Bessie's score was the total number of lines she had drawn.
In order to win in the game, Bessie found you and wanted you to help her calculate the maximum possible score.
Input
* Line 1th: Enter 1 positive integers: N
* 2nd. N+1 Line: Line i+1 with 2 spaces separated by the integer x_i, y_i, describes the coordinates of point I
Output
Line 1th: Output 1 integers, indicating the maximum score for Bessie, the number of straight lines that she can draw in parallel to each other
Sample Input4
-1 1
-2 0
0 0
1 1
Sample Output4HINT
Output Description: Bessie can draw the following 4 lines of slope: -1,0,1/3 and 1.
Source
Silver
Solution
Enumeration two points directly to calculate, set to go to a weight just fine. T don't tell me you don't ask for the slope.
Oh, I'm using pair<int to prevent accuracy errors, int> means slope.
1#include <bits/stdc++.h>2 using namespacestd;3typedef pair<int,int>PII;4 Set<pii>S;5 intx[1005], y[1005];6 7 intgcdintIintj)8 {9 returnJ? GCD (j, I%j): I;Ten } One A intMain () - { - intN, dx, DY, g; theCIN >>N; - for(inti =1; I <= N; i++) -CIN >> X[i] >>Y[i]; - for(inti =1; I <= N; i++) + for(intj = i +1; J <= N; J + +) - { +DX = X[i]-X[j]; ADY = y[i]-Y[j]; atg =gcd (dx, dy); -DX/= g, dy/=G; - S.insert (make_pair (dx, dy)); - } -cout << s.size () <<Endl; - return 0; in}
View Code
[BZOJ1610] [Usaco2008 Feb] Line tethered Game (set)