码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2606 Rabbit hunt【简单几何】

时间:2016-08-14 13:11:47      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:


Rabbit hunt
Time Limit: 1000MS   Memory Limit: 65536K
Total 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

6
7 122
8 139
9 156
10 173
11 190
-100 1

Sample Output

5

Source


原题链接: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;
}


POJ 2606 Rabbit hunt【简单几何】

标签:

原文地址:http://blog.csdn.net/hurmishine/article/details/52203797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!