Codeforces Round #198 (Div. 2)B. Maximal Area Quadrilateral(4边形面积)

平面有n个点 求最大边形的面积

It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide.

枚举对角线, 求对角线两边最大三角形面积,最后相加。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
struct Point{
    double x,y;
}p[500];
struct edge{
    Point x,y;
}e;
double xmulti(Point p1,Point p2,Point p0){
    return (p1.x-p0.x)*(p2.y-p0.y)-(p1.y-p0.y)*(p2.x-p0.x);
}
int side(Point p1,edge e){
    return xmulti(e.x,p1,e.y)>1e-6;
}
double area(Point a,Point b,Point c){
    return fabs(xmulti(a,b,c)/2);
}
int main(){
    int n,i,j,k;
    double s1,s2,s;
    while(scanf("%d",&n)!=EOF){
        for(i=0;i<n;i++){
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        s=0.0;
        for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                s1=0.0;s2=0.0;
                e.x=p[i];e.y=p[j];
                for(k=0;k<n;k++){
                    if(side(p[k],e)>0)s1=max(s1,area(p[i],p[j],p[k]));
                    else s2=max(s2,area(p[i],p[j],p[k]));
                }
                if(s1>1e-6&&s2>1e-6)s=max(s,s1+s2);
            }
        }
        printf("%lf\n",s);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值