zoukankan      html  css  js  c++  java
  • BZOJ2338: [HNOI2011]数矩形

    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
    ",ans);
    }
    
    
  • 相关阅读:
    Android开发学习一:环境搭建
    Python Challenge
    Python Challenge
    Python Challenge
    Centos中的mysql安装以及配置
    linux查询日志内容命令
    搭建elasticsearch过程中遇到的问题
    启动kafka后闪退
    zookeeper环境搭建
    nginx安装
  • 原文地址:https://www.cnblogs.com/suika/p/10205515.html
Copyright © 2011-2022 走看看