Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6559 | Accepted: 2440 |
Description
Farmer John has challenged Bessie to the following game: FJ has a board with dots marked at N (2 ≤ N ≤ 200) 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 two of the dots and drawing a straight line between them; however, she is not allowed to draw a line if she has already drawn another line that is parallel to that line. Bessie would like to know her chances of winning, so she has 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 two space-separated integers: Xi and Yi.
Output
* Line 1: A single integer representing the maximal number of lines Bessie can draw, no two of which are parallel.
Sample Input
4 -1 1 -2 0 0 0 1 1
Sample Output
4
n个点最多确定多少个互不平行的直线,求出每两个点间的斜率,排序后判断即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#define inf 0x3f3f3f3f
#define N 201
#define eps 1e-6
#define PI acos(-1.0)
using namespace std;
struct Point
{
double x, y;
} p[N];
double a[N*N];
int n;
double FindSlewRate(Point p1, Point p2)
{
Point p;
p.x = p2.x - p1.x;
p.y = p2.y - p1.y;
if(abs(p.x) < eps) return PI / 2; //斜率不存在
double tmp = atan(p.y / p.x);
if(tmp < 0) return PI + tmp;
return tmp;
}
int cmp(const void *c, const void *d)
{
return *(double *)c > *(double *)d ? 1 : -1;
}
int main()
{
while(~scanf("%d", &n))
{
for(int i = 0; i < n; i++)
{
scanf("%lf%lf", &p[i].x, &p[i].y);
}
int rt = 0;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
a[rt++] = FindSlewRate(p[i], p[j]);
}
}
qsort(a,rt,sizeof(a[0]),cmp);
int ans = 1;
for(int i = 1; i < rt; i++)
{
if(a[i] != a[i-1])
ans++;
}
printf("%d\n", ans);
}
return 0;
}