1069: [SCOI2007]最大土地面积

1069: [SCOI2007]最大土地面积

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 2506   Solved: 955
[ Submit][ Status][ Discuss]

Description

  在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成
的多边形面积最大。

Input

  第1行一个正整数N,接下来N行,每行2个数x,y,表示该点的横坐标和纵坐标。

Output

  最大的多边形面积,答案精确到小数点后3位。

Sample Input

5
0 0
1 0
1 1
0 1
0.5 0.5

Sample Output

1.000

HINT

数据范围 n<=2000, |x|,|y|<=100000

Source

[ Submit][ Status][ Discuss]




  对角线可以枚举,然后就是在两边各找一个最大面积三角形,显然三角形顶点具有单调性(同旋转卡壳)故旋转卡壳

  写的时候。。一开始Cross函数左右傻傻分不清楚,然后,凸包里面的点是不能有重复的

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
 
const int maxn = 2E3 + 20;
typedef double DB;
const DB eps = 1E-10;
 
struct P{
    DB x,y;
    bool operator < (const P &b) const {
        if (x < b.x) return 1;
        if (x > b.x) return 0;
        return y < b.y;
    }
     
    P operator - (const P &b) {
        P ret; ret.x = x - b.x; ret.y = y - b.y;
        return ret;
    }
}p[maxn],q[maxn*2];
 
DB Cross(P v,P w) {return v.x*w.y - v.y*w.x;}
DB Dot(P v,P w) {return v.x*w.x + v.y*w.y;}
 
int n,cnt;
DB ans;
 
bool cmp(DB A)
{
    if (A < 0) return 1;
    if (abs(A) < eps) return 1;
    return 0;
}
 
int main()
{
    #ifdef YZY
           freopen("land10.in","r",stdin);
    #endif
     
    cin >> n;
    for (int i = 1; i <= n; i++) scanf("%lf%lf",&p[i].x,&p[i].y);
    sort(p + 1,p + n + 1);
    for (int i = 1; i <= n; i++) {
        while (cnt > 1 && cmp(Cross(q[cnt]-q[cnt-1],p[i]-q[cnt-1]))) --cnt;
        q[++cnt] = p[i];
    } 
    int k = cnt;
    for (int i = n - 1; i; i--) {
        while (cnt > k && cmp(Cross(q[cnt]-q[cnt-1],p[i]-q[cnt-1]))) --cnt;
        q[++cnt] = p[i];
    }
    for (int i = 0; i < cnt; i++) q[i] = q[i+1]; --cnt;
    for (int x = 0; x < cnt; x++) {
        int a,b; a = (x+1)%cnt; b = (x+3)%cnt;
        for (int y = x + 2; y < cnt; y++) {
            while ((a+1)%cnt != y && Cross(q[a]-q[x],q[y]-q[x]) < Cross(q[(a+1)%cnt]-q[x],q[y]-q[x]))
                a = (a+1)%cnt;
            while ((b+1)%cnt != x) {
                DB A = Cross(q[y]-q[x],q[b]-q[x]);
                DB B = Cross(q[y]-q[x],q[(b+1)%cnt]-q[x]);
                if (A < B) b = (b+1)%cnt; else break;
            }
                 
            ans = max(ans,Cross(q[a]-q[x],q[y]-q[x]) + Cross(q[y]-q[x],q[b]-q[x]));
        }
    }
    printf("%.3f",ans/2);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值