POJ 3668 Game of Lines(n点最多有多少不平行直线)

Game of Lines
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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值