poj 3668 Game of Lines

来源:互联网 发布:澳门电信网络plmn 编辑:程序博客网 时间:2024/05/22 14:54
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 00 01 1

Sample Output

4

【题意】
给你很多点,每两个点构成一条直线,问你不平行的直线有多少条。

【分析】
简单暴力

【代码】

#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <set>using namespace std;typedef struct{    double x,y;}P;P poi[205];double ans_size[40010];int num=0;int main(){//    freopen("in.txt","r",stdin);    int t;    scanf("%d",&t);    for(int i=0;i<t;i++)    {        scanf("%lf %lf",&poi[i].x,&poi[i].y);        for(int j=0;j<i;j++)        {            if(fabs(poi[i].x-poi[j].x)>1e-6)                ans_size[num++]=(poi[i].y-poi[j].y)/(poi[i].x-poi[j].x);            else                ans_size[num++]=10000000;        }    }    sort(ans_size,ans_size+num);    int count = 1;    for(int i=1;i<num;i++)    {        if(fabs(ans_size[i]-ans_size[i-1])>1e-8)            count++;    }    printf("%d\n",count);    return 0;}