让我看到你们的双手
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;
}