您的位置:首页 > 其它

HDU:1432 Lining Up(数学)

2016-04-10 22:57 375 查看


Lining Up

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 1304 Accepted Submission(s): 370



Problem Description

``How am I ever going to solve this problem?" said the pilot.

Indeed, the pilot was not facing an easy task. She had to drop packages at specific points scattered in a dangerous area. Furthermore, the pilot could only fly over the area once in a straight line, and she had to fly over as many points as possible. All points
were given by means of integer coordinates in a two-dimensional space. The pilot wanted to know the largest number of points from the given set that all lie on one line. Can you write a program that calculates this number?

Your program has to be efficient!

Input

The input consists of multiple test cases, and each case begins with a single positive integer on a line by itself indicating the number of points, followed by N pairs of integers, where 1 < N < 700. Each pair of integers is separated by one blank and ended
by a new-line character. No pair will occur twice in one test case.

Output

For each test case, the output consists of one integer representing the largest number of points that all lie on one line, one line per case.

Sample Input

5
1 1
2 2
3 3
9 10
10 11


Sample Output

3


Source

ACM暑期集训队练习赛(四)

Recommend

lcy

题目大意,给你n个点的坐标,看最多有多少个点在同一直线上。

暴力枚举,看i、j点斜率与j、k点斜率是否相等即可,看代码。

#include <stdio.h>
struct node
{
double x,y;
};
struct node zuobiao[750];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&zuobiao[i].x,&zuobiao[i].y);
}
if(n==2)//俩点直接就只有俩
{
printf("2\n");
continue;
}
int max=-1;
for(int i=0;i<n-2;i++)
{
for(int j=i+1;j<n;j++)
{
int cnt=2;//刚开始已经有了i、j俩点
for(int k=j+1;k<n;k++)
{
if((zuobiao[i].x-zuobiao[j].x)*(zuobiao[i].y-zuobiao[k].y)==(zuobiao[i].x-zuobiao[k].x)*(zuobiao[i].y-zuobiao[j].y))//i、j两点斜率=i、k两点斜率
{
cnt++;
}
}
if(cnt>max)
{
max=cnt;
}
}

}
printf("%d\n",max);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数学 暴力