1. 程式人生 > >codeforces340B(叉積)

codeforces340B(叉積)

#include <stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int n;
struct Node {
	double x;
	double y;
}p[maxn];
double muti(Node p1, Node p2, Node p3)
{
	double a1, b1, a2, b2;
	a1 = p2.x - p1.x, a2 = p3.x - p2.x;
	b1 = p2.y - p1.y, b2 = p3.y - p2.y;
	return a1*b2 - a2*b1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	double ans = 0;
	for (int i = 1; i <= n; i++)
		cin >> p[i].x >> p[i].y;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			double s1 = 0, s2 = 0;
			for (int k = 1; k <= n; k++) {
				double S = muti(p[i], p[j], p[k]);
				if (S > 0)
					s1 = max(s1, S / 2);
				else {
					S = -S;
					s2 = max(s2, S / 2);
				}
			}
			if (s1>0 && s2>0)//兩個三角形都必須有面積才行,否則有可能把三角形的面積算出來,不會出現列舉處>4邊形的情況,因為if語句是在第二個for迴圈內的
				ans = max(ans, s1 + s2);
		}
	}
	printf("%.6lf\n", ans);
	return 0;
}

解析過兩天再補充吧