BZOJ 1356 计算几何 解题报告

这是一篇关于BZOJ 1356题目的解题报告,题目要求从给定的n个点中找出能构成最大面积矩形的四个点。输入包含n个点的坐标,输出最大矩形的面积。解题策略是暴力枚举,通过判断找到最佳组合。样例输入给出了8个点,输出的最大面积为10。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

让我看到你们的双手
356: [Baltic2009]Rectangle

Description

给出n个点,要你从这些点中找出四个点来组成一个矩形,面积最大.

Input

第一行给出N.4 ≤ n ≤ 1,500. 下面N行给出这些点的坐标,其值在 [10^8,10^8]

Output

最大的矩形面积

Sample Input

8
-2 3
-2 -1
0 3
0 -1
1 -1
2 1
-3 1
-2 1

Sample Output

10

HINT
这里写图片描述

【解题报告】

暴力乱搞题,暴力枚举圆,再暴力判断

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 1510

int n;
double ans;
struct Point
{
    int x,y;
    Point(){}
    Point(int _x,int _y):x(_x),y(_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);}
    double operator*(const Point &a)const
    {return (double)x*a.x+(double)y*a.y;}
}p[N];
struct Circle
{
    int x,y,len;
    int no1,no2; 
}c[N*N>>1];

bool cmp(Circle a,Circle b)
{return(a.x==b.x)?((a.y==b.y)?a.len<b.len:a.y<b.y):a.x<b.x;}
bool equal(Circle a,Circle b)
{return a.x==b.x&&a.y==b.y&&a.len==b.len;}
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(p[c[i].no1],p[c[j].no1]);
        double l2=get_dis(p[c[j].no1],p[c[i].no2]);
        ans=max(ans,l1*l2); 
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d%d",&p[i].x,&p[i].y);
    int tot=0;
    for(int i=1;i<=n;++i)
    for(int j=1;j<i;++j)
    {
        c[++tot].x=p[i].x+p[j].x;
        c[tot].y=p[i].y+p[j].y;
        c[tot].len=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);
        c[tot].no1=i,c[tot].no2=j;  
    }       
    sort(c+1,c+tot+1,cmp);
    int j;
    for(int i=1;i<=tot;i=j+1)
    {
        j=i;
        while(equal(c[i],c[j+1])) ++j;
        calc(i,j);
    }
    printf("%.0lf\n",ans);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值