您的位置:首页 > 其它

hdu1432

2016-04-07 17:58 323 查看
Lining Up
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU
1432

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
解体思路:利用向量共线定理,暴力枚举。代码如下:#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int x[710],y[710];
int main(){
int n,i,j,k,sum,ans;
while(scanf("%d",&n)!=EOF){
ans=0;sum=0;
for(i=1;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
for(i=1;i<=n;i++){//i点为公共端点
for(j=i+1;j<=n;j++){
ans=0;
for(k=j+1;k<=n;k++){
if((x[j]-x[i])*(y[k]-y[i])-(x[k]-x[i])*(y[j]-y[i])==0)
ans++;
}
sum=sum>ans?sum:ans;

}
}
printf("%d\n",sum+2);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: