luogu P1452 Beauty Contest

在这里插入图片描述

anayisis

这是一道毒瘤题
留坑待补~~(赶作业去了)~~

code

#include<bits/stdc++.h>
#define EPS 1e-8
#define convex Conv
using namespace std;
template<typename T>void read(T &x){
    x=0;char r=getchar();T neg=1;
    while(r>'9'||r<'0'){if(r=='-')neg=-1;r=getchar();}
    while(r>='0'&&r<='9'){x=(x<<3)+(x<<1)+r-'0';r=getchar();}
    x*=neg;
}
double max(double a, double b)
{
    return a > b ? a : b;
}
struct node{
    double x;double y;
    node():x(0),y(0){}
    node(double x,double y):x(x),y(y){}
};
/*inline bool cmp(node a,node b){
    if(a.x==b.x)return a.y<b.y;//
    return a.x<b.x;
}*/
bool cmp(const node p1, const node p2)//比较函数,不用极角,用坐标(x, y); 
{
    return ((p1.y == p2.y && p1.x < p2.x) || p1.y < p2.y);//找最左下角的点为最小点
}
inline node vec(node start,node end){
    return node(end.x-start.x,end.y-start.y);
}
inline double cro(node x1,node x2){
    return (x1.x*x2.y-x2.y*x1.x);
}
inline double dis(node a,node b){
    return ((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
}
int sgn(double x)
{
    if (fabs(x) < EPS)
        return 0;
    return x < 0 ? -1 : 1;
}
double x_multi(node p1, node p2, node p3)
{
    return ((p3.x - p1.x) * (p2.y - p1.y) - (p2.x - p1.x) * (p3.y - p1.y));
}
int n;//
int len;
const int maxn=50000+10;
node p[maxn];
node Conv[maxn];
inline void Andrew(){
    int top=1;
    Conv[0]=p[0];
    Conv[1]=p[1];
    for(int i=2;i<n;++i){
        while(top>0&&sgn(x_multi(Conv[top - 1], Conv[top], p[i])) <= 0){//sgn(cro(vec(Conv[top-1],Conv[top]),vec(Conv[top],p[i])))<=0){
            --top;
        }
        Conv[++top]=p[i];
    }
    int tmp=top;
    for(int i=n-2;i>=0;--i){
        while(top>tmp&&sgn(x_multi(Conv[top - 1], Conv[top], p[i])) <= 0){//sgn(cro(vec(Conv[top-1],Conv[top]),vec(Conv[top],p[i])))<=0){
            --top;
        }
        Conv[++top]=p[i];
    }
    //for(int i=0;i<=top;i++)printf("%.0f, %.0f\n",Conv[i].x,Conv[i].y);
    len=top;
}
inline void rotating_calipers(){
    double ans=0;
    int _p=1;
    //int q=1;
    Conv[n]=Conv[0];
    for(int i=0;i<=len;++i){
        while (x_multi(convex[i],convex[i+1],convex[_p+1])>x_multi(convex[i],convex[i+1],convex[_p]))//while(cro(vec(p[i],p[i+1]),vec(p[i],p[_p]))<cro(vec(p[i],p[i+1]),vec(p[i],p[_p+1]))){
            _p=(_p+1)%len;
        
        ans=max(ans,(max(dis(convex[_p],convex[i]),dis(convex[_p+1],convex[i+1]))));
    }/*for (int p = 0; p < n; p++)
    {
        while (x_multi(convex[p], convex[p + 1], convex[q + 1]) > x_multi(convex[p], convex[p + 1], convex[q]))
            q = (q + 1) % n;
        ans = max(ans, max(dis(convex[p], convex[q]), dis(convex[p + 1], convex[q + 1])));//ans为距离的平方
    }*/
    printf("%.0lf\n",ans);
}
int main(){
    //freopen("datain2.txt","r",stdin);
    read(n);
    for(int i=0;i<n;++i){scanf("%lf%lf",&p[i].x,&p[i].y);}
    sort(p,p+n,cmp);
    Andrew();
    rotating_calipers();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AndrewMe8211

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值