首页 > 代码库 > POJ2079:Triangle

POJ2079:Triangle

传送门

POJ的G++怎么这么辣鸡啊,卡了很长时间。

当时一看数据范围:$N \leq 50000$,就开始往$O(N)$的算法上想。之前做凸包内最大面积四边形是枚举对踵点然后在两边分别找到面积最大的三角形拼接在一起。

所以就直接枚举对踵点然后推进第三个点。

结果wa成一条狗,发现被Discuss里的一组数据给hack掉了。

然后看了别人$O(N)$的做法,似乎是有问题的。

所以索性就直接$O(N^2)$了,谁叫数据水呢hhhh

枚举凸包上任意两个点,推进第三个点统计答案即可。

//POJ2079//by Cydiater//2017.1.30#include <iostream>#include <cstdio>#include <cmath>#include <ctime>#include <cstring>#include <string>#include <queue>#include <map>#include <iomanip>#include <cstdlib>#include <algorithm>#include <bitset>#include <set>#include <vector>using namespace std;#define ll long long#define up(i,j,n)	for(int i=j;i<=n;i++)#define down(i,j,n)	for(int i=j;i>=n;i--)#define cmax(a,b)	a=max(a,b)#define cmin(a,b)	a=min(a,b)#define db 		double#define Vector 		Pointconst int MAXN=1e5+5;const int oo=0x3f3f3f3f;const db eps=1e-10;inline int read(){	char ch=getchar();int x=0,f=1;	while(ch>‘9‘||ch<‘0‘){if(ch==‘-‘)f=-1;ch=getchar();}	while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}	return x*f;}struct Point{	db x,y;	Point(db x=0,db y=0):x(x),y(y){}};Vector operator + (Point x,Point y){return Vector(x.x+y.x,x.y+y.y);}Vector operator - (Point x,Point y){return Vector(x.x-y.x,x.y-y.y);}Vector operator * (Vector x,db p){return Vector(x.x*p,x.y*p);}Vector operator / (Vector x,db p){return Vector(x.x/p,x.y/p);}int dcmp(db x){if(fabs(x)<eps)return 0;else return x<0?-1:1;}bool operator < (Vector x,Vector y){return dcmp(x.x-y.x)==0?x.y<y.y:x.x<y.x;}bool operator == (Vector x,Vector y){return dcmp(x.x-y.x)==0&&dcmp(x.y-y.y)==0;}int N,top,A;db ans;Point V[MAXN],q[MAXN];namespace solution{	Point Write(){db x=read(),y=read();return Point(x,y);}	db Cross(Vector x,Vector y){return x.x*y.y-x.y*y.x;}	void Prepare(){		N=read();if(N==-1)exit(0);		up(i,1,N)V[i]=Write();		sort(V+1,V+N+1);		N=unique(V+1,V+N+1)-(V+1);	}	void Andrew(){		top=0;		up(i,1,N){			while(top>=2&&Cross(q[top]-q[top-1],V[i]-q[top-1])<=0)top--;			q[++top]=V[i];		}		int lim=top;		down(i,N-1,1){			while(top-lim>=1&&Cross(q[top]-q[top-1],V[i]-q[top-1])<=0)top--;			q[++top]=V[i];					}	}	void Solve(){		Andrew();		top--;		ans=0;		up(i,1,top){			int pos=2;			up(j,i+1,top){				while(fabs(Cross(q[pos+1]-q[j],q[i]-q[j]))>fabs(Cross(q[pos]-q[j],q[i]-q[j])))(pos%=top)++;				cmax(ans,fabs(Cross(q[pos]-q[j],q[i]-q[j]))/2);			}		}		printf("%.2lf\n",ans);	}}int main(){	//freopen("input.in","r",stdin);	using namespace solution;	while(true){		Prepare();		Solve();	}	return 0;}

 

POJ2079:Triangle