POJ-1118 极角排序 尺取

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

Input consist several case,First line of the each case is an integer N ( 1 < N < 700 ),then follow N pairs of integers. Each pair of integers is separated by one blank and ended by a new-line character. The input ended by N=0.
Output

output one integer for each input case ,representing the largest number of points that all lie on one line.
Sample Input

5
1 1
2 2
3 3
9 10
10 11
0
Sample Output

3

#include<iostream>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxp=5e4+7;
const double inf=1e200;
const double eps=1e-8;
const double pi =acos(-1.0);
int sgn(double x){
	if(fabs(x)<eps)return 0;
	return x>0?1:-1;
}
double hypot(double x,double y){return sqrt(x*x+y*y);}
struct Point{
	double x,y;
	Point(double x=0,double y=0):x(x),y(y){}
	bool operator ==(const Point& b){return !sgn(x-b.x)&&!sgn(y-b.y);}
	bool operator  <(const Point& b)const{return !sgn(x-b.x)?y<b.y:x<b.x;}
	double operator^(const Point& b){return x*b.y-y*b.x;}//叉积
	double operator*(const Point& b){return x*b.x+y*b.y;}//点积
	Point operator +(const Point& b){return Point(x+b.x,y+b.y);}
	Point operator -(const Point& b){return Point(x-b.x,y-b.y);}
	Point operator *(const double& k){return Point(x*k,y*k);}
	Point operator /(const double& k){return Point(x/k,y/k);}
	double len(){return hypot(x,y);}
	double len2(){return x*x+y*y;}
	double rad(Point a,Point b){Point p=*this;return fabs(atan2(fabs((a-p)^(b-p)),(a-p)*(b-p)));}//pa和pb夹角
	double angle(){return atan2(y,x);}//倾斜角
	double angle(Point B){//夹角
		Point A=(*this);
		return acos(A*B/A.len()/B.len());
	}
	double distance(Point b){return hypot(x-b.x,y-b.y);}
	void input(){scanf("%lf%lf",&x,&y);}
	void show(){printf("(%.2lf %.2lf)\n",x,y);}
	void zero(){
		if(!sgn(x))x=0.0;
		if(!sgn(y))y=0.0;
	}
};
struct cmp{
	Point p;
	cmp(const Point &p0){p=p0;}
	bool operator()(const Point &aa,const Point &bb){
		Point a=aa,b=bb;
		int d=sgn((a-p)^(b-p));
		if(!d)return sgn(a.distance(p)-b.distance(p))<0;
		return d>0;
	}
};
double cross(Point a,Point b,Point c){return (b-a)^(c-a);}
int main(){
	int n;
	while(scanf("%d",&n),n){
		vector<Point>p(n),tmp(n);
		int ans=2;
		for(int i=0;i<n;++i)p[i].input(),tmp[i]=p[i];
		for(int i=0;i<n;++i){
			sort(p.begin(),p.end(),cmp(tmp[i]));
			int j=1,k=2;
			while(k<n){
				while(k<n&&!sgn(cross(p[0],p[j],p[k])))++k;
				ans=max(ans,k-j+1);
				if(k==n)break;
				j=k++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值