zoukankan      html  css  js  c++  java
  • 最大空凸包

    #pragma GCC optimize(2)
    #pragma GCC optimize(3, "Ofast", "inline")
    
    #include<bits/stdc++.h>//最大空凸包
    
    #define ll long long
    #define met(a, x) memset(a,x,sizeof(a))
    
    using namespace std;
    const double pi = acos(-1.0);
    typedef struct Point {
        int x, y;
    
        Point() {}
    
        Point(int x, int y) : x(x), y(y) {}
    
        Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }
    
        Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }
    
        int operator*(const Point &b) const { return x * b.y - y * b.x; }
    
        int len() const { return x * x + y * y; }
    
        int operator<(const Point &a) const {
            if ((*this) * a > 0 || (*this) * a == 0 && len() < a.len())
                return 1;
            return 0;
        }
    } Point;
    int n;
    Point s[122], p[122];
    int dp[122][122];
    
    int Jud(int m) {
        int ans, i, j, now, k, flag, S;
        memset(dp, 0, sizeof(dp));
        ans = 0;
        for (i = 2; i <= m; i++) {
            now = i - 1;
            while (now >= 1 && p[i] * p[now] == 0)
                now--;
            flag = 0;
            if (now == i - 1)
                flag = 1;
            while (now >= 1) {
                S = p[now] * p[i];
                k = now - 1;
                while (k >= 1 && (p[now] - p[i]) * (p[k] - p[now]) > 0)
                    k--;
                if (k >= 1)
                    S += dp[now][k];
                if (flag)
                    dp[i][now] = S;
                ans = max(ans, S);
                now = k;
            }
            if (flag == 0)
                continue;
            for (j = 1; j <= i - 1; j++)
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
        }
        return ans;
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int _, i, j, m, ans;
        cin >> _;
        while (_--) {
            cin >> n;
            for (i = 1; i <= n; i++)
                cin >> s[i].x >> s[i].y;
            ans = 0;
            for (i = 1; i <= n; i++) {
                m = 0;
                for (j = 1; j <= n; j++) {
                    if (s[j].y > s[i].y || s[j].y == s[i].y && s[j].x >= s[i].x)
                        p[++m] = s[j] - s[i];
                }
                sort(p + 1, p + m + 1);
                ans = max(ans, Jud(m));
            }
            cout << fixed << setprecision(1) << (ans/2.0) << endl;
        }
        return 0;
    }
  • 相关阅读:
    闭包的最准确的解释-待翻译
    undefined 和 null 的异同
    Javascript深度克隆一个对象
    产品培训的经验
    JavaScript库开发者们的规则
    IOS ——UI篇—— UITableView的常用属性及代理方法的用法总结
    IOS ——UI篇—— 自定义UITableViewCell的方法
    IOS ——UI篇—— UIScrollView的用法总结
    使用UIKit中的tag属性要注意的
    IOS ——UI篇——UITabBarController的基本用法
  • 原文地址:https://www.cnblogs.com/nublity/p/11618239.html
Copyright © 2011-2022 走看看