zoukankan      html  css  js  c++  java
  • bzoj 1132 POI2008 Tro

        大水题=_=,可我想复杂了……

        很裸的暴力,就是加了个小优化……

        叉积求面积 :abs(xi*yj - yi*xj) 所以去掉绝对值,把 xi 和 xj 提出来就可以求和了

        去绝对值加个极角排序,每次把最左边的点当成原点,然后剩下的排序,接着枚举第二个点,求叉积之和……

        坐标都是整数,用long long,最后再除2

        上代码:

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #define N 3010
    using namespace std;
    
    struct sss
    {
        long long x, y;
    }dian[N], now, zan[N];
    int n;
    long long ans = 0;
    
    long long chaji(sss x, sss y)
    {
        return (x.x-now.x)*(y.y-now.y) - (x.y-now.y)*(y.x-now.x);
    }
    
    bool cmp1(sss x, sss y) { return x.x == y.x ? x.y < y.y : x.x < y.x; }
    bool cmp2(sss x, sss y ){ return chaji(x, y) > 0; }
    
    int main()
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%lld%lld", &dian[i].x, &dian[i].y);
        sort(dian+1, dian+1+n, cmp1);
        for (int i = 1; i <= n-2; ++i)
        {
            now = dian[i];
            long long ty = 0, tx = 0;
            for (int j = i+1; j <= n; ++j) zan[j] = dian[j];
            sort(zan+i+1, zan+1+n, cmp2);
            for (int j = i+1; j <= n; ++j)
            {
                ty += zan[j].y-now.y;
                tx += zan[j].x-now.x;
            }
            for (int j = i+1; j <= n-1; ++j)
            {
                ty -= zan[j].y-now.y; tx -= zan[j].x-now.x;
                ans += (zan[j].x-now.x)*ty - (zan[j].y-now.y)*tx;
            }
        }
        if (ans % 2) printf("%lld.5
    ", ans/2);
        else printf("%lld.0
    ", ans/2);
    }
  • 相关阅读:
    删除 node_modules文件夹cmd指令
    vue 限制输入字符长度
    vertical-align和text-align属性实现垂直水平居中
    二分查找法
    MySQL实现分页查询
    数据库连接
    AOP编程的常用实现方式
    链表中环的入口
    AQS同步组件及ReentrantLock和synchronized的区别
    快速排序的递归和非递归
  • 原文地址:https://www.cnblogs.com/handsomeJian/p/4006136.html
Copyright © 2011-2022 走看看