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!
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;
}
//很简单脑残的题目吧,但是就是坑,希望你们不要上当受骗了