您的位置:首页 > 其它

BZOJ 2338: [HNOI2011]数矩形

2016-04-06 15:35 423 查看
先处理出一共O(n^2)条线段

然后找出长度相等,中点重合的线段,更新答案即可

事实上这么做极端情况下会被卡成n^3的复杂度,不过数据没有特殊构造还是能过的(其实是我也不会其他方法了)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1500+5;
ll sqr(ll x){return x*x;}
struct point{
ll x,y;
bool operator < (const point &rhs)const{
if(x==rhs.x)return y<rhs.y;
return x<rhs.x;
}
bool operator == (const point &rhs)const{
return x==rhs.x&&y==rhs.y;
}
};
struct seg{
ll l;point p;
int p1,p2;
bool operator < (const seg &rhs)const{
if(l==rhs.l)return p<rhs.p;
return l<rhs.l;
}
bool operator == (const seg &rhs)const{
return l==rhs.l&&p==rhs.p;
}
};
point operator + (point a,point b){
return (point){a.x+b.x,a.y+b.y};
}
point operator - (point a,point b){
return (point){a.x-b.x,a.y-b.y};
}
ll length(point a,point b){
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
point p
;
seg s[N*N/2];
#define iabs(x) (x>0?x:-x)
ll cross(point a,point b){
return a.x*b.y-a.y*b.x;
}
ll cross(point a,point b,point c){
return cross(b-a,c-a);
}
ll area(point a,point b,point c){
return iabs(cross(a,b,c));
}
int main(){
//freopen("a.in","r",stdin);
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%lld%lld",&p[i].x,&p[i].y);
int tot=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
s[++tot]=(seg){length(p[i],p[j]),p[i]+p[j],i,j};
sort(s+1,s+1+tot);
ll ans=0;
for(int i=1;i<=tot;i++)
for(int j=i-1;j>=1&&s[i]==s[j];j--)
ans=max(ans,area(p[s[i].p1],p[s[i].p2],p[s[j].p1]));
printf("%lld\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: