[POJ2187]Beauty Contest

Title:

I am a hyperlink

Explanation:

It is worth mentioning that this is a "non-directional" algorithm, why, because the name of ta may not be haha, rotating cards have a total of 2*3*2*2=24 different pronunciations oh

Rotating chuck can solve: the farthest point pair of convex polygons, the farthest/nearest point pair between convex polygons, and the minimum matrix coverage problem.

The point-to-point pair on the convex hull is called the heel-to-heel point, which is stuck by a pair of parallel lines.
The answer must come from a pair of heels.
Try to enumerate all heel points by rotating a pair of parallel lines
Enumerating an edge on a convex hull in counterclockwise order, the farthest point of the straight line from the convex hull to the edge rotates monotonously counterclockwise, which is equivalent to a vertex opposite a straight line card.
Let's start with the first one: the farthest point pair, you can see that the farthest point pair must be on the convex hull.
Core operation, the judgment in the long and long while is to change the distance from the point to the straight line into the judgment of the triangle area.

void rotating()
{
    stack[top+1]=stack[1];
    int now=2;
    for (int i=1;i<=top;i++)
    {
        while (dcmp(cj(dian[stack[i+1]]-dian[stack[i]],dian[stack[now]]-dian[stack[i]]) -
         cj(dian[stack[i+1]]-dian[stack[i]],dian[stack[now+1]]-dian[stack[i]]))<0)
           now=now%top+1;
        ans=max(ans,len(dian[stack[now]]-dian[stack[i]]));
    }
}

This rounding output technique is worth learning.

Code:

#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps=1e-9;
int dcmp(double x)
{
    if (x<=eps && x>=-eps) return 0;
    return (x>0)?1:-1;
}
struct po
{
    double x,y;
    po (double X=0,double Y=0){x=X;y=Y;}
}dian[50005];
int n,top,stack[50005];double ans;
bool operator <(const po &a,const po&b){return a.x<b.x||(a.x==b.x && a.y<b.y);}
po operator -(po x,po y){return po(x.x-y.x,x.y-y.y);}
double cj(po x,po y){return x.x*y.y-x.y*y.x;}
void tb()
{
    sort(dian+1,dian+n+1);
    top=0;
    for (int i=1;i<=n;i++)
    {
        while (top>1 && dcmp(cj(dian[stack[top]]-dian[stack[top-1]],dian[i]-dian[stack[top-1]]))<=0) top--;
        stack[++top]=i;
    }
    int k=top;
    for (int i=n-1;i>=1;i--)
    {
        while (top>k && dcmp(cj(dian[stack[top]]-dian[stack[top-1]],dian[i]-dian[stack[top-1]]))<=0) top--;
        stack[++top]=i;
    }
    if (n>1) top--;
}
double len(po x){return sqrt(x.x*x.x+x.y*x.y);}
void rotating()
{
    stack[top+1]=stack[1];
    int now=2;
    for (int i=1;i<=top;i++)
    {
        while (dcmp(cj(dian[stack[i+1]]-dian[stack[i]],dian[stack[now]]-dian[stack[i]]) - cj(dian[stack[i+1]]-dian[stack[i]],dian[stack[now+1]]-dian[stack[i]]))<0)
        now=now%top+1;
        ans=max(ans,len(dian[stack[now]]-dian[stack[i]]));
    }
}
int main()
{
    double x,y;
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%lf%lf",&x,&y);
        dian[i]=po(x,y);
    }
    tb();
    rotating();
    printf("%.0lf\n",ans*ans);
}

Posted by joshuamd3 on Thu, 07 Feb 2019 09:42:17 -0800