【codeforces 340B】Maximal Area Quadrilateral

【题目链接】:http://codeforces.com/problemset/problem/340/B

【题意】

给你n个点,让你在这里面找4个点构成一个四边形;
求出最大四边形的面积;

【题解】

枚举四边形的对角线上的对顶点;
然后再枚举每一个点;
看看这个点是在这条线的哪一侧;
是左侧和右侧;
是左侧的话;
看看这3个点构成的三角形有没有比当前获取的左侧的三角形大;
右侧的话同理;
最后把两侧得到的最大的三角形合在一起;
就是最大的四边形了;
O(N 3 ) 

【Number Of WA

0

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 310;

int n,x[N],y[N],ans;

int main(){
    //Open();
    Close();//scanf,puts,printf not use
    //init??????
    cin >> n;
    rep1(i,1,n){
        cin >> x[i] >> y[i];
    }
    rep1(i,1,n-1){
        rep1(j,i+1,n){
            int temp1 = -1,temp2 = -1;
            int x1 = x[i],y1 = y[i],x2 = x[j],y2 = y[j];
            int vx1 = x2-x1,vy1 = y2-y1;
            rep1(k,1,n)
            if (k!=i && k!=j){
                int x3 = x[k],y3 = y[k];
                int vx2 = x3-x1,vy2 = y3-y1;
                /*
                    vx1 vy1
                    vx2 vy2
                */
                int chaji = vx1*vy2-vx2*vy1;
                if (chaji<0){
                    temp1 = max(temp1,-chaji);
                }else if(chaji>0){
                    temp2 = max(temp2,chaji);
                }
            }
            if (temp1>0 && temp2 >0)
                ans = max(ans,temp1+temp2);
        }
    }
    cout << fixed << setprecision(10) << 1.0*ans*0.5<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626265.html