zoukankan      html  css  js  c++  java
  • bzoj 1132 几何

    思路:我刚开始算三角形的方法是原点叉积三条边,然后计算每条边向量积的贡献,但是对于同一条线上的点

    有时候没有办法抵消掉。。。。。

    看网上的思路是对于一个三角形的面积通过两条边的叉积获得,然后枚举一个点,排序去掉公式的绝对值,记录

    后缀和进行计算。。。

    看的这篇博客。。

    https://www.cnblogs.com/GXZlegend/p/7509699.html

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define pii pair<int,int>
    #define piii pair<int, pair<int,int> >
    
    using namespace std;
    
    const int N = 3000 + 10;
    const int M = 10 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    const double eps = 1e-7;
    
    int n;
    
    LL sufx[N], sufy[N], ans;
    
    struct Point {
        int x, y;
        Point(int x = 0, int y = 0) {
            this->x = x;
            this->y = y;
        }
    
        Point operator - (const Point &rhs) {
            return Point(x - rhs.x, y - rhs.y);
        }
    } p[N], q[N];
    
    bool cmp1(const Point &a, const Point &b) {
        return a.x == b.x ? a.y < b.y : a.x < b.x;
    }
    
    bool cmp2(const Point &a, const Point &b) {
        return a.y * b.x < b.y * a.x;
    }
    
    
    int main()
    {
        scanf("%d", &n);
    
        for(int i = 1; i <= n; i++) {
            scanf("%lld%lld", &p[i].x , &p[i].y);
        }
    
        sort(p + 1, p + n + 1, cmp1);
    
        for(int i = 1; i <= n; i ++) {
    
            for(int j = i + 1; j <= n ;j++) {
                q[j] = p[j] - p[i];
            }
    
            sort(q + i + 1, q + n + 1, cmp2);
    
            for(int j = n; j > i; j--)
            {
                sufx[j] = sufx[j + 1] + q[j].x;
                sufy[j] = sufy[j + 1] + q[j].y;
                ans += q[j].x * sufy[j + 1] - q[j].y * sufx[j + 1];
            }
        }
    
        if(ans & 1) printf("%lld.5
    ", ans / 2);
        else printf("%lld.0
    ", ans / 2);
        return 0;
    }
  • 相关阅读:
    Nightingale 加发邮件功能
    Centos7 系统进程解析
    Nightingale 夜莺监控系统 安装
    iptables:应用防火墙规则:ptables-restore: line xxx failed [失败]
    CAD2011卸载不干净 无法重装问题
    Make Globle HS 全局热备
    Swarm工具使用
    docker-registry构建私有的镜像仓库
    MySQL Replication
    javascript 设计模式之单例模式
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9190678.html
Copyright © 2011-2022 走看看