3707: 圈地

3707: 圈地

Time Limit: 10 Sec   Memory Limit: 128 MB
Submit: 229   Solved: 85
[ Submit][ Status][ Discuss]

Description

2维平面上有n个木桩,黄学长有一次圈地的机会并得到圈到的土地,为了体现他的高风亮节,他要使他圈到的土地面积尽量小。圈地需要圈一个至少3个点的多边形,多边形的顶点就是一个木桩,圈得的土地就是这个多边形内部的土地。(因为黄学长非常的神,所以他允许圈出的第n点共线,那样面积算0)

Input

第一行一个整数n,表示木桩个数。
接下来n行,每行2个整数表示一个木桩的坐标,坐标两两不同。

Output

仅一行,表示最小圈得的土地面积,保留2位小数。

Sample Input

3
0 0
0 1
1 0

Sample Output

0.50

HINT

对于100%的数据,n<=1000。

Source

[ Submit][ Status][ Discuss]

网上正解一大堆啦。。。但是一个都看不懂
不过此题有一个有趣的暴力方法,将所有点按照x坐标第一关键字,y坐标第二关键字排序
每大概50个点分成一个小块,块内暴力枚举尝试更新答案
但是这样的做法肯定是挂的,因为两块之间的点对并没有枚举
不过,可以随机旋转坐标轴,再重复上面的操作,执行100次一般就能出正解了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
 
const int maxn = 1010;
typedef double DB;
 
struct Point{
    DB x,y; Point(){}
    Point (DB x,DB y): x(x),y(y){}
    bool operator < (const Point &B) const
    {
        if (x < B.x) return 1;
        if (x > B.x) return 0;
        return y < B.y;
    }
    Point operator - (const Point &B) {return Point(x - B.x,y - B.y);}
}p[maxn],q[maxn];
typedef Point Vector;
 
int n;
DB Ans = 1E16;
 
int max(const int &x,const int &y) {return x > y ? x : y;}
DB Cross(const Vector &v1,const Vector &v2) {return v1.x * v2.y - v2.x * v1.y;}
 
void Calc(int l,int r)
{
    for (int i = l; i <= r; i++)
        for (int j = i + 1; j <= r; j++)
            for (int k = j + 1; k <= r; k++)
                Ans = min(Ans,fabs(Cross(q[j] - q[i],q[k] - q[i])));
}
 
int main()
{
    #ifdef DMC
        freopen("DMC.txt","r",stdin);
    #endif
     
    cin >> n; int siz = 50;
    for (int i = 1; i <= n; i++) scanf("%lf%lf",&p[i].x,&p[i].y);
    for (int I = 0; I < 100; I++)
    {
        DB alpha = (DB)(rand() - rand()) / 233.00;
        DB Cos = cos(alpha),Sin = sin(alpha); //printf("%.8lf %.8lf\n",Cos,Sin);
        for (int i = 1; i <= n; i++)
            q[i] = Point(p[i].x * Cos - p[i].y * Sin,p[i].x * Sin + p[i].y * Cos);
        sort(q + 1,q + n + 1); int last = 1,tot = 0;
        for (int i = 1; i <= n; i++)
        {
            ++tot;
            if (tot == siz || i == n) Calc(last,i),tot = 0,last = i + 1;
        }
    }
    printf("%.2f\n",Ans / 2.00);
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值