hdu1432lining up之坑爹题

Problem Description
``How am I ever going to solve this problem?" said thepilot. 
Indeed, the pilot was not facing an easy task. She had to droppackages at specific points scattered in a dangerous area.Furthermore, the pilot could only fly over the area once in astraight line, and she had to fly over as many points as possible.All points were given by means of integer coordinates in atwo-dimensional space. The pilot wanted to know the largest numberof points from the given set that all lie on one line. Can youwrite a program that calculates thisnumber? 
Your program has to be efficient!
Input
The input consists of multiple test cases, and each case beginswith a single positive integer on a line by itself indicating thenumber of points, followed by N pairs of integers, where 1 < N< 700. Each pair of integers is separated by one blank and endedby a new-line character. No pair will occur twice in one testcase. 
Output
For each test case, the output consists of one integer representingthe largest number of points that all lie on one line, one line percase.
 
Sample Input
 
   
5 1 12 2 3 3 9 10 10 11
 
Sample Output
 
   
3

这是一道经典的简单的几何了,可是我是从来没做过几何,所以有点不只从何下手,于是上网找代码,找不到,坑逼,直接问学长了。
一条直线上的任意一对向量存在x1*y2+x2y1==0;
然后枚举就OK了,<700*700*700是能够的,但是有点肯的就是不知道为何scanf不行,但是cin就可以,所以恕我无知,只能骂作者坑爹了。
代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
#define N 750

int main()
{
    int n;
    int i, j, k;
    int x[N],y[N];
    while ( cin>>n&& n)//(传说中的坑爹)
    {
       for (i=0; i
          scanf("%d%d",&x[i],&y[i]);
       int sum = 0;
       //直接枚举
       for (i=0; i
       {
           for(j=i+1; j
           {
              int num = 0;
              for (k=j+1; k
                 if ((x[j] - x[i])* (y[k] - y[i]) - (y[j] -y[i])* (x[k] - x[i]) == 0)
                    num++;
              sum = sum > num ? sum :num;
           }
       }
      printf("%d\n",sum+2);//至于为什么要加2呢?因为我们num记录的时候本身就是少了两个点的,而且至少可以经过两点
    }
    return 0;
}


//很简单脑残的题目吧,但是就是坑,希望你们不要上当受骗了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值