BZOJ 1356 [Baltic2009]Rectangle 数学

题意:
平面上n个点,求选出四个点构成矩形的最大面积。
解析:
四个点构成矩形有个性质,
就是四点共圆,并且两条对角线都是直径。
所以我们可以考虑首先预处理出来任意两点所确定的圆。
然后我们只需要在同一个圆中暴力枚举成对的点对即可。
处理圆的话,避免小数我们可以考虑使横纵坐标乘2,直径平方即可。
为什么这个复杂度敢写呢?
我们只需要考虑一个圆上能有多少对整点呢?
我虽然不会计算但是应该不会有很多。
所以我们的复杂度是O(n*n>>1*(k*k>>1))
k为圆上的整点对。
不虚。。
代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1510
using namespace std;
typedef long long ll;
int n;
double ans;
struct Point
{
    int x,y;
    Point(){}
    Point(int _x,int _y):x(_x),y(_y){}
    friend istream& operator >> (istream &_,Point &a)
    {scanf("%d%d",&a.x,&a.y);return _;}
    Point operator + (const Point &a)
    {return Point(x+a.x,y+a.y);}
    Point operator - (const Point &a)
    {return Point(x-a.x,y-a.y);}
    double operator * (const Point &a)
    {return (double)x*a.x+(double)y*a.y;}
}pt[N];
struct Cir
{
    int x,y,len;
    int no1,no2;
}cir[(N*N)>>1];
bool cmp(Cir a,Cir b)
{
    if(a.x==b.x)
    {
        if(a.y==b.y)
        {
            return a.len<b.len;
        }else return a.y<b.y;
    }else return a.x<b.x;
}
bool operator == (Cir a,Cir b)
{
    if(a.x==b.x&&a.y==b.y&&a.len==b.len)return 1;
    return 0;
}
double get_dis(Point a,Point b)
{
    return sqrt((a-b)*(a-b));
}
void calc(int l,int r)
{
    if(l==r)return ;
    for(int i=l;i<=r;i++)
    {
        for(int j=l;j<i;j++)
        {
            double l1=get_dis(pt[cir[i].no1],pt[cir[j].no1]);
            double l2=get_dis(pt[cir[j].no1],pt[cir[i].no2]);
            ans=max(ans,l1*l2);
        }
    }
}
int tot;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)cin>>pt[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            int x=pt[i].x+pt[j].x;
            int y=pt[i].y+pt[j].y;
            int len=(pt[i].x-pt[j].x)*(pt[i].x-pt[j].x)+(pt[i].y-pt[j].y)*(pt[i].y-pt[j].y);
            cir[++tot].x=x,cir[tot].y=y,cir[tot].len=len,cir[tot].no1=i,cir[tot].no2=j;
        }
    }
    sort(cir+1,cir+tot+1,cmp);
    int j;
    for(int i=1;i<=tot;i=j+1)
    {
        j=i;
        while(cir[i]==cir[j+1])j++;
        calc(i,j);
    }
    printf("%.0lf\n",ans);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值