Game of Lines
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 6555 |
|
Accepted: 2439 |
Description
Farmer John had challenged Bessie to the following GAME:FJ have a board with dots marked at N (2≤ n ≤2 XX) distinct lattice points. Dot i has the integer coordinates XI and Yi ( -1,000≤ xi ≤ 1,000; -1,000≤ yi ≤1,000).
Bessie can score a point in the game by picking, the dots and drawing a straight line between them; However, she was not allowed to draw a line if she had already drawn another line. Bessie would like to know hers chances of winning, so she had asked you to help find the maximum score she can obtain.
Input
* Line 1: A single integer: N
* Lines 2. N+1:line i+1 describes lattice point i with the space-separated integers: Xi and Yi.
Output
* Line 1: A single integer representing the maximal number of lines Bessie can draw, No. of which is parallel.
Sample Input
4-1 1-2 00) 01 1
Sample Output
4
Source
Usaco February Silver However, the problem is just a simple enumeration. Enumerates a point and another point match, and records the slope of the line, ignoring if any slope has been found. Note: Since the line may be parallel to the y-axis (that is, x[i] = = X[j]), this is set to infinity (however just 231-1).
#include <cstdio>#include<cstring>#include<Set>using namespacestd;intx[205];inty[205];intN;Set<Double>s;intMain () {scanf ("%d", &N); for(inti =0; I < n; ++i) scanf ("%d%d", &x[i], &Y[i]); intAns =0; S.clear (); for(inti =0; I < n; ++i) for(intj = i +1; J < N; ++j) {DoubleK; if(X[i]-x[j] = =0) K =0x7fffffff; ElseK = (Double) (Y[i]-y[j])/(X[i]-X[j]); if(!S.count (k)) { ++ans; S.insert (k); }} printf ("%d\n", ans); return 0;}
"POJ 3668" Game of Lines