【计算几何】P3217 [HNOI2011]数矩形

here
要在n个点中选中4个点求一个矩形的最大面积。

如果枚举点的话复杂度实在太高了,想法就是枚举边,一个矩形的对角线的边的中点是相等的,而且他们的长度也必定相等。

边的数量最多是n*n还是可以接受的

我们计算出来所有的边,然后首先根据距离排序然后根据中间点的位置排序,最后计算面积的时候要用叉积计算防止爆long long的情况发生。

kuangbin的板子还是看着不太习惯,这几天适应一下吧!下边是我自己写的不是他的板子。

ac code

//god with me
#include <bits/stdc++.h>
#define sc(x) cerr << #x << ": " << x << '\n'
#define fg cerr << "----------------------" << el
#define el '\n'
#define hh putchar('\n')
#define pb push_back
#define db double
#define ld long double
#define ll long long
#define int long long
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
const double pi = acos(-1.0);
const int maxp = 1010;


const int N=1505;

struct point
{
    int x,y;
    point(){}
    point (int _x,int _y)
    {
        x=_x;
        y=_y;
    }
    ll operator ^(const point &a) const
    {
        return x*a.y-a.x*y;
    }
    point operator +(const point &a)const
    {
        return point(x+a.x,y+a.y);
    }
    point operator-(const point &a)const
    {
        return point(x-a.x,y-a.y);
    }
    bool operator<(const point &a)const
    {
        if(x!=a.x)return x<a.x;
        else return y<a.y;
    }
    bool operator==(const point &a)const
    {
        return x==a.x&&y==a.y;
    }
}P[N];

struct line
{
    point mid;
    point v;
    ll d;
}L[N*N];

bool comp(line a,line b)
{
    return a.d==b.d?a.mid.x==b.mid.x?a.mid.y<b.mid.y:a.mid.x<b.mid.x:a.d>b.d;
}

ll sq(int x)
{
    return x*x;
}

ll dis(int a,int b)
{
    return sq(P[a].x-P[b].x)+sq(P[a].y-P[b].y);
}

void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        P[i]={x,y};
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            L[++cnt]={P[i]+P[j],P[i]-P[j],dis(i,j)};
        }
    }
    sort(L+1,L+cnt+1,comp);
    ll ans=0;
    for(int i=1,j=1;i<=cnt;i=j)
    {
        while(L[i].d==L[j].d&&L[i].mid==L[j].mid)j++;
        for(int k=i;k<j;++k)
        {
            for(int t=k+1;t<j;++t)
                ans=max(ans,abs(L[k].v^L[t].v)>>1);
        }
    }
    cout<<ans<<endl;
}

signed main()
{
    int T=1;
    for(int i=1;i<=T;i++)
    {
        solve();
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

while WA er

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

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

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

打赏作者

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

抵扣说明:

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

余额充值