zoukankan      html  css  js  c++  java
  • [SCOI2007]最大土地面积

    嘟嘟嘟


    无意间看到了一个计算几何。


    (n <= 2000)就很愉快了。枚举求完凸包后(O(n ^ 2))枚举对角线,然后另两个点用旋转卡壳维护就完事了。
    结果数据(或是题意)坑人,有的有重复的点,如果选了两个重复的点的话就算成三角形了(凭什么),所以应该求一个最简凸包(就是点最少)。


    哎,本来十几分钟就写完了的,因为这个坑爹错误找了半天。

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 2e3 + 5;
    inline ll read()
    {
      ll ans = 0;
      char ch = getchar(), last = ' ';
      while(!isdigit(ch)) last = ch, ch = getchar();
      while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
      if(last == '-') ans = -ans;
      return ans;
    }
    inline void write(ll x)
    {
      if(x < 0) x = -x, putchar('-');
      if(x >= 10) write(x / 10);
      putchar(x % 10 + '0');
    }
    
    int n;
    struct Point
    {
      db x, y;
      In Point operator + (const Point& oth)const
      {
        return (Point){x + oth.x, y + oth.y};
      }
      In Point operator - (const Point& oth)const
      {
        return (Point){x - oth.x, y - oth.y};
      }  
      In db operator * (const Point& oth)const
      {
        return x * oth.y - y * oth.x;
      }
      friend In db dis(Point A)
      {
        return A.x * A.x + A.y * A.y;
      }
    }p[maxn], S;
    
    In bool cmp(Point& A, Point& B)
    {
      db s = (A - S) * (B - S);
      if(fabs(s) > eps) return s > eps;
      return dis(A - S) < dis(B - S);
    }
    int st[maxn], top = 0;
    In void Graham()
    {
      S = p[1];
      for(int i = 2; i <= n; ++i)
        if(p[i].x < S.x || (fabs(p[i].x - S.x) < eps && p[i].y < S.y)) S = p[i];
      sort(p + 1, p + n + 1, cmp);
      for(int i = 1; i <= n; ++i)
        {
          while(top > 1 && (p[st[top]] - p[st[top - 1]]) * (p[i] - p[st[top - 1]]) < eps) --top;
          st[++top] = i;
        }
    }
    
    db ans = 0;
    In db calc(Point A, Point B, Point C, Point D)
    {
      return ((B - A) * (C - A) + (C - A) * (D - A)) * 0.5;
    }
    In int nxt(int x) {return x + 1 > top ? 1 : x + 1;}
    In void Rota()
    {
      for(int i = 1; i <= top; ++i)
        {
          int k = i, h = nxt(nxt(i));
          for(int j = nxt(nxt(i)); nxt(nxt(j)) ^ i; j = nxt(j))
    	{
    	  while(nxt(k) != j && (p[st[k]] - p[st[i]]) * (p[st[j]] - p[st[i]]) < (p[st[nxt(k)]] - p[st[i]]) * (p[st[j]] - p[st[i]])) k = nxt(k);
    	  while(nxt(h) != i && (p[st[j]] - p[st[i]]) * (p[st[h]] - p[st[i]]) < (p[st[j]] - p[st[i]]) * (p[st[nxt(h)]] - p[st[i]])) h = nxt(h);
    	  ans = max(ans, calc(p[st[i]], p[st[k]], p[st[j]], p[st[h]]));
    	}
        }
    }
    
    int main()
    {
      n = read();
      for(int i = 1; i <= n; ++i) scanf("%lf %lf", &p[i].x, &p[i].y);
      Graham(); Rota();
      printf("%.3lf
    ", ans);
      return 0;
    }
    
  • 相关阅读:
    常用连链接命令行存储小工具
    switch case 跳转表
    抖音越狱版本App下载
    AutoLayout + UILabel布局
    ReplayKit2 有线投屏项目-反向Socket实现
    ReplayKit2 有线投屏项目总结
    直播相关-搭建直播流服务器nodejs
    难过!失眠!
    CAShapeLayer
    WebService相关概念介绍
  • 原文地址:https://www.cnblogs.com/mrclr/p/10388272.html
Copyright © 2011-2022 走看看