BZOJ2338: [HNOI2011]數矩形
阿新 • • 發佈:2019-01-01
mes cst != type algorithm long cto std pre
BZOJ2338: [HNOI2011]數矩形
https://lydsy.com/JudgeOnline/problem.php?id=2338
分析:
- 一個容易想出的做法就是把線段按中點和長度排序,把相等的放在一起處理。
- 這樣做的復雜度是\(O(n^2logn+矩形個數)\)的。
- 矩形個數是\(O(n^{2.5})\)的。
代碼:
#include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <vector> #include <iostream> #include <cmath> using namespace std; #define N 1550 #define eps 1e-8 typedef long long ll; ll pf(ll x) {return x*x;} struct Point { ll x,y; Point() {} Point(ll x_,ll y_) {x=x_,y=y_;} bool operator < (const Point &p) const { return x==p.x ? y<p.y : x<p.x; } Point operator - (const Point &p) const {return Point(x-p.x,y-p.y);} }a[N]; ll dis(const Point &p1,const Point &p2) {return pf(p1.x-p2.x)+pf(p1.y-p2.y);} ll cross(const Point &p1,const Point &p2) {return p1.x*p2.y-p1.y*p2.x;} struct A { Point p1,p2,p3; bool operator < (const A &u) const { ll tmp=dis(p1,p2)-dis(u.p1,u.p2); return tmp==0 ? p3<u.p3 : tmp<0; } }b[N*N]; int n; ll ans; int main() { scanf("%d",&n); int i,j,k; int m=0; for(i=1;i<=n;i++) scanf("%lld%lld",&a[i].x,&a[i].y); for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) { Point p3=Point((a[i].x+a[j].x),(a[i].y+a[j].y)); b[++m]=(A){a[i],a[j],p3}; } sort(b+1,b+m+1); j=1; for(i=2;i<=m;i++) { for(;j<i&&(dis(b[j].p1,b[j].p2)!=dis(b[i].p1,b[i].p2)||b[j].p3<b[i].p3||b[i].p3<b[j].p3);j++) ; for(k=j;k<i;k++) { ans=max(ans,abs(cross(b[k].p1-b[i].p1,b[k].p2-b[i].p1))); } } printf("%lld\n",ans); }
BZOJ2338: [HNOI2011]數矩形