zoukankan      html  css  js  c++  java
  • {bzoj2338 [HNOI2011]数矩形 && NBUT 1453 LeBlanc}平面内找最大矩形

    思路:

    1. 枚举3个点,计算第4个点并判断是否存在,复杂度为O(N3logN)或O(N3α)
    2. 考虑矩形的对角线,两条对角线可以构成一个矩形,它们的长度和中点必须完全一样,于是将所有线段按长度和中点排序,那么所有可能构成矩形的线段(对角线)一定在连续的区间内,顺序枚举即可,复杂度O(N2logN)。
      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    #pragma comment(linker, "/STACK:10240000")
    #include <map>
    #include <set>
    #include <cmath>
    #include <ctime>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    #define X                   first
    #define Y                   second
    #define pb                  push_back
    #define mp                  make_pair
    #define all(a)              (a).begin(), (a).end()
    #define fillchar(a, x)      memset(a, x, sizeof(a))
    #define copy(a, b)          memcpy(a, b, sizeof(a))
    
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef unsigned long long ull;
    
    #ifndef ONLINE_JUDGE
    void RI(vector<int>&a,int n){a.resize(n);for(int i=0;i<n;i++)scanf("%d",&a[i]);}
    void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>
    void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?1:-1;
    while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>
    void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
    void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>
    void print(T*p, T*q){int d=p<q?1:-1;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
    #endif
    template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
    template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);}
    
    const double PI = acos(-1.0);
    const int INF = 1e9 + 7;
    const double EPS = 1e-12;
    
    /* -------------------------------------------------------------------------------- */
    
    const int maxn = 1e2 + 7;
    
    struct Point {
        int x, y;
        Point(int x, int y) {
            this->x = x;
            this->y = y;
        }
        Point operator + (const Point &that) const {
            return Point(x + that.x, y + that.y);
        }
        Point operator - (const Point &that) const {
            return Point(x - that.x, y - that.y);
        }
        inline ll sqr(ll a) {
            return a * a;
        }
        ll dist(const Point &that) {
            return sqr(x - that.x) + sqr(y - that.y);
        }
        bool operator < (const Point &that) const {
            return x == that.x? y < that.y : x < that.x;
        }
        bool operator == (const Point &that) const {
            return x == that.x && y == that.y;
        }
        Point() {}
    };
    
    struct Line {
        Point a, b, mid;
        ll len;
        Line(Point a, Point b) {
            this->a = a;
            this->b = b;
            mid = a + b;
            len = a.dist(b);
        }
        Line() {}
        bool operator < (const Line &that) const {
            return len == that.len? mid < that.mid : len < that.len;
        }
    };
    vector<Line> line;
    Point p[maxn];
    
    bool equal(const Line &a, const Line &b) {
        return a.len == b.len && a.mid == b.mid;
    }
    
    ll cross(Point a, Point b) {
        return (ll)a.x * b.y - (ll)a.y * b.x;
    }
    
    ll Area(const Line &a, Line &b) {
        return abs(cross(a.a - a.b, b.a - b.b) / 2);
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #endif // ONLINE_JUDGE
        int n;
        while (cin >> n) {
            for (int i = 0; i < n; i ++) {
                scanf("%d%d", &p[i].x, &p[i].y);
            }
            line.clear();
            for (int i = 0; i < n; i ++) {
                for (int j = i + 1; j < n; j ++) {
                    line.pb(Line(p[i], p[j]));
                }
            }
            sort(all(line));
            ll area = - 1;
            for (int i = 1; i < line.size(); i ++) {
                for (int j = i - 1; j >= 0 && equal(line[i], line[j]); j --) {
                    umax(area, Area(line[i], line[j]));
                }
            }
            if (area < 0) puts("No Eyes");
            else cout << area << ".0000" << endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Vue.js学习笔记(8)拖放
    Vue.js学习笔记(7)组件详解
    使用了与请求的协议不兼容的地址的解决办法
    修改machine.config遇到System.Net.ServicePointManager 的类型初始值设定项引发异常
    未找到路径“/Agent/SissQrTemplate/AddN”的控制器或该控制器未实现 IController。
    C# .NET 2.0 判断当前程序进程是否为64位运行时 (x64)
    荣耀9开启虚拟按键
    C# .NET 4.5 将多个文件添加到压缩包中
    开IE时 暴卡
    VMware Workstation 安装 mac OS 时遇到 不可恢复错误: (vcpu-0)
  • 原文地址:https://www.cnblogs.com/jklongint/p/4749346.html
Copyright © 2011-2022 走看看