LOJ#6544. 杀苍蝇(计算几何)

题面

传送门

题解

枚举一个定点,把剩下的所有点按照极角排序就行了

//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=2005;const double eps=1e-8,Pi=acos(-1.0);
inline double abs(const double &x){return x<-eps?-x:x;}
inline int sgn(const double &x){return x<-eps?-1:x>eps;}
struct node{
	int x,y;double k;
	inline node(){}
	inline node(R int xx,R int yy):x(xx),y(yy){}
	inline node operator +(const node &b)const{return node(x+b.x,y+b.y);}
	inline node operator -(const node &b)const{return node(x-b.x,y-b.y);}
	inline bool operator <(const node &b)const{return k<b.k;}
	inline double K(){return atan2(y,x);}
}p[N],st[N];
int n,res,top;
void solve(int id){
	top=0;
	fp(i,1,id-1)st[++top]=p[i]-p[id];
	fp(i,id+1,n)st[++top]=p[i]-p[id];
	fp(i,1,top){
		st[i].k=st[i].K();
		if(sgn(st[i].k)<=0)st[i].k+=Pi;
	}
	sort(st+1,st+1+top);
	for(R int i=1,j=1;i<=n;i=j+1){
		while(j+1<=n&&!sgn(st[j+1].k-st[i].k))++j;
		cmax(res,j-i+1+1);
	}
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read();
	fp(i,1,n)p[i].x=read(),p[i].y=read();
	fp(i,1,n)solve(i);
	printf("%d
",res);
	return 0;
}
原文地址:https://www.cnblogs.com/bztMinamoto/p/10709261.html