POJ 2606 Rabbit hunt【简单几何】

来源:互联网 发布:淘宝直通车有用吗 编辑:程序博客网 时间:2024/05/18 06:53


Rabbit hunt
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 8015 Accepted: 3993

Description

A good hunter kills two rabbits with one shot. Of course, it can be easily done since for any two points we can always draw a line containing the both. But killing three or more rabbits in one shot is much more difficult task. To be the best hunter in the world one should be able to kill the maximal possible number of rabbits. Assume that rabbit is a point on the plane with integer x and y coordinates. Having a set of rabbits you are to find the largest number K of rabbits that can be killed with single shot, i.e. maximum number of points lying exactly on the same line. No two rabbits sit at one point.

Input

An input contains an integer N (2<=N<=200) specifying the number of rabbits. Each of the next N lines in the input contains the x coordinate and the y coordinate (in this order) separated by a space (-1000<=x,y<=1000).

Output

The output contains the maximal number K of rabbits situated in one line.

Sample Input

67 1228 1399 15610 17311 190-100 1

Sample Output

5

Source

Ural State University collegiate programming contest 2000

原题链接:http://poj.org/problem?id=2606

这题和上一篇博客的那个题目差不多,就输入有点不同。

AC代码;

#include <iostream>#include <cstdio>using namespace std;struct Point{    int x,y;}a[705];int main(){    int n;    //freopen("data/2606.txt","r",stdin);    while(cin>>n)    {        for(int i=0;i<n;i++)            scanf("%d%d",&a[i].x,&a[i].y);            //cin>>a[i].x>>a[i].y;        int maxx=2;        for(int i=0;i<n;i++)        {            for(int j=i+1;j<n;j++)            {                int ans=2;                for(int k=j+1;k<n;k++)                {                    if((a[j].x-a[i].x)*(a[k].y-a[j].y)==(a[j].y-a[i].y)*(a[k].x-a[j].x))                        ans++;                    if(ans>maxx)                        maxx=ans;                }            }        }        cout<<maxx<<endl;    }    return 0;}


0 0
原创粉丝点击