zoukankan      html  css  js  c++  java
  • 【bzoj2338】[HNOI2011]数矩形 计算几何

    题目描述


    题解

    计算几何

    由于对角线平分且相等的四边形是矩形,因此我们可以把每条对角线存起来,按照对角线长度和中点位置为关键字排序,这样对于每个相同长度和中点的对角线就排到了一起。

    于是对于每段可能形成矩形的区间暴力即可。

    时间复杂度$O(cnt)$,$cnt$为矩形个数。根据大爷讲的某定理,$cnt<O(n^2sqrt n)$,可以A掉本题。

    注意本题任何时候都不能使用double,否则炸精度无限WA。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define N 1510
    using namespace std;
    typedef long long ll;
    struct data
    {
        ll len , px , py , dx , dy;
        bool operator<(const data &a)const {return len == a.len ? px == a.px ? py < a.py : px < a.px : len < a.len;}
    }a[N * N];
    ll x[N] , y[N];
    int tot;
    ll calc(int i , int j)
    {
        return abs(a[i].dx * a[j].dy - a[i].dy * a[j].dx) >> 1;
    }
    int main()
    {
        int n , i , j , k , l;
        ll ans = 0;
        scanf("%d" , &n);
        for(i = 1 ; i <= n ; i ++ )
        {
            scanf("%lld%lld" , &x[i] , &y[i]);
            for(j = 1 ; j < i ; j ++ )
            {
                a[++tot].len = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
                a[tot].px = x[i] + x[j] , a[tot].py = y[i] + y[j];
                a[tot].dx = x[i] - x[j] , a[tot].dy = y[i] - y[j];
            }
        }
        sort(a + 1 , a + tot + 1);
        for(i = j = 1 ; i <= tot ; i = j)
        {
            while(a[j].len == a[i].len && a[j].px == a[i].px && a[j].py == a[i].py) j ++ ;
            for(k = i ; k < j ; k ++ )
                for(l = k + 1 ; l < j ; l ++ )
                    ans = max(ans , calc(k , l));
        }
        printf("%lld
    " , ans);
        return 0;
    }
    
  • 相关阅读:
    跨域资源共享 CORS 详解
    C# 每月第一天和最后一天
    jexus http to https
    ASP.NET MVC 路由学习
    jexus
    centos7 添加开机启动项
    jexus docker
    HTTP2.0新特性
    jexus配置支持Owin
    Autofac Named命名和Key Service服务
  • 原文地址:https://www.cnblogs.com/GXZlegend/p/7391318.html
Copyright © 2011-2022 走看看