Triangle 两次旋转卡壳

136 篇文章 0 订阅
8 篇文章 0 订阅
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int X = 50001;
struct node{
    int x,y;
    friend bool operator < (node a,node b)
    {
        return a.y<b.y||(a.y==b.y&&a.x<b.x);
    }
}res[X],p[X];
int n,top;
int cross(node a,node b,node o)
{
    return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y);
}
void graham()
{
    sort(p,p+n);
    res[0] = p[0];
    res[1] = p[1];
    top = 1;
    for(int i=2;i<n;i++)
    {
        while(top&&cross(p[i],res[top-1],res[top])<=0)
            --top;
        res[++top] = p[i];
    }
    int ntop = top;
    res[++top] = p[n-2];
    for(int i=n-3;i>=0;i--)
    {
        while(top>ntop&&cross(p[i],res[top-1],res[top])<=0)
            --top;
        res[++top] = p[i];
    }
}
void solve()
{
    if(top<3)
    {
        printf("0.00\n");
        return;
    }
    int k = 2;
    int ans = 0;
    int temp;
    for(int i=0;i<top;i++)
    {
        k = (i+1)%top;
        for(int j=i+1;j<top;j++)
        {
            while(cross(res[i],res[j],res[k+1])>(temp = cross(res[i],res[j],res[k])))
                k = (k+1)%top;
            ans = max(ans,temp);
        }
    }
    printf("%.2lf\n",ans/2.0);
}
int main()
{
    while(scanf("%d",&n),n!=-1)
    {
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        if(n<3)
        {
            printf("0.00\n");
            continue;
        }
        graham();
        solve();
    }
    return 0;
}
 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值