BZOJ 3707 圈地

闲扯

BZOJ权限题,没有权限,哭了
然后DBZ不知道怎么回事,\(O(n^3)\)直接压过去了。。。

备忘

叉积的计算公式\(x_1y_2\)

思路

n^3

暴力枚举显然

n^2

正解的思路有点神,好吧是我太弱
首先考虑如果有两个点共线了,那么最小的面积一定是里这条线最近的那个点得来的
然后考虑把所有直线找出,按斜率排序,从一条直线变到另一条直线的时候,与下一条直线的距离顺序会改变的一定是这条直线的两个端点,如果改变,交换这两个端点即可

代码

只有\(O(n^3)\)

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const double eps=1e-8;
int n;
double ans=1e9;
struct Point{
    double x,y;
    Point(double xx=0,double yx=0){
        x=xx;
        y=yx;
    }
}a[1111];
struct Vector{
    double x,y;
    Vector(double xx=0,double yx=0){
        x=xx;
        y=yx;
    }
};
Vector operator - (Point a,Point b){
    return Vector(b.x-a.x,b.y-a.y);
}
double corss(Vector x,Vector y){//x cross y
    return abs(x.x*y.y-y.x*x.y);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lf %lf",&a[i].x,&a[i].y);
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++)
            for(int k=j+1;k<=n;k++)
                ans=min(ans,corss(a[j]-a[i],a[k]-a[i]));
    }
    printf("%.2lf\n",ans/2);
    return 0;
}
posted @ 2019-02-28 17:19  dreagonm  阅读(167)  评论(0编辑  收藏  举报