hdu1432

来源:互联网 发布:路由器域名重定向设置 编辑:程序博客网 时间:2024/04/30 06:25
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

51 12 23 39 1010 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;}


0 0
原创粉丝点击