ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[SCOI2007]最大土地面积

2019-02-16 17:04:02  阅读:294  来源: 互联网

标签:oth SCOI2007 const Point 面积 db 土地 return include


嘟嘟嘟


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


\(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\n", ans);
  return 0;
}

标签:oth,SCOI2007,const,Point,面积,db,土地,return,include
来源: https://www.cnblogs.com/mrclr/p/10388272.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有