poj 2780 Linearity
2011-11-22 13:09
197 查看
Linearity
Description
Alice often examines star maps where stars are represented by points in a plane and there is a Cartesian coordinate for each star. Let the Linearity of a star map be the maximum number of stars in a straight line.
For example, look at the star map shown on the figure above, the Linearity of this map is 3, because the star 1, star 2, and star 5 are within the same straight line, and there is no straight line that passes 4 stars.
You are to write a program to find the Linearity of a star map.
Input
Input will contain multiple test cases. Each describes a star map.
For each test case, the first line of the input contains the number of stars N (2 <= N <= 1000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0 <= X, Y <= 1000). There can be only one star at one point of the plane.
Output
Output the Linearity of the map in a single line.
Sample Input
Sample Output
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 6722 | Accepted: 1499 |
Alice often examines star maps where stars are represented by points in a plane and there is a Cartesian coordinate for each star. Let the Linearity of a star map be the maximum number of stars in a straight line.
For example, look at the star map shown on the figure above, the Linearity of this map is 3, because the star 1, star 2, and star 5 are within the same straight line, and there is no straight line that passes 4 stars.
You are to write a program to find the Linearity of a star map.
Input
Input will contain multiple test cases. Each describes a star map.
For each test case, the first line of the input contains the number of stars N (2 <= N <= 1000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0 <= X, Y <= 1000). There can be only one star at one point of the plane.
Output
Output the Linearity of the map in a single line.
Sample Input
5 0 0 2 0 0 2 1 1 2 2
Sample Output
3
#include<iostream> #include<algorithm> using namespace std; double k[1002]; double x[1002],y[1002]; int main() { int n; int i,j,p; int cnt; int num,max_num; while(cin>>n) { for(i=0;i<n;i++) { cin>>x[i]; cin>>y[i]; } num=2; max_num=2; for(i=0;i<n;i++) { cnt=0; for(j=0;j<n;j++) { if(i==j) continue; if(x[i]==x[j]) k[cnt]=999999999; else { k[cnt]=(y[i]-y[j])/(x[i]-x[j]); } cnt++; } sort(k,k+cnt); num=2; for(p=1;p<cnt;p++) { if(k[p]==k[p-1]) { num++; if(max_num<num) max_num=num; } else { num=2; if(max_num<num) max_num=num; } } } cout<<max_num<<endl; } return 0; }
相关文章推荐
- poj 2780 Linearity 最多共线点经典问题
- POJ 2780 Linearity
- poj 2780 Linearity 【高效版 同一条直线上的点】
- (Relax ST1.13)POJ 2780 Linearity(给出若干个点,求最多有多少个点共线,不能使用n^3算法)
- poj 1118 Lining Up || poj 2780 Linearity || poj 2606 Rabbit hunt
- POJ 2780 Linearity
- POJ 1118+2606+2780 (求平面上同一条直线的最多点数)
- pku 2780 Linearity
- POJ 1118,2606,2780,3512
- POJ 求平面点阵中的最大共线点数系列 (POJ 1118 + 2606 + 2780)
- POJ 2780
- POJ 1118+2606+2780(同一直线上点最多的数目)
- 【同一直线最多点】 poj 1118+2606+2780
- poj 2253 Frogger
- POJ 3621 Sightseeing Cows
- poj 1061 青蛙的约会
- 【poj - 1953 World Cup Noise】
- POJ1004 Financial Management
- POJ-3517-And Then There Was One
- POJ 3372 Candy Distribution