Given a set of vertices in a plane, this question requires you to find the largest of multiple triangles. Generally, if you have never touched the computational ry, you must first consider enumeration.
Yes, I think it's correct. However, the enumeration here is not enumerated in the set of the original vertex. We need to perform some processing. This processing is to find the convex hull, and then follow
The order of vertices appears on the convex hull to enumerate, so that the speed will come up. Think about it and you will know that the three vertices with the largest triangle will always be on the convex hull, so as to reduce unnecessary enumeration.
Point
# Include <iostream> # include <stdio. h> # include <string. h >#include <algorithm> # include <cmath> using namespace STD; # define EPS 1e-6 # define PI 3.14159265 struct point {Double X; Double Y;} po [100000], temp; int N, Pos; bool zero (double A) {return FABS (a) <EPS;} double DIS (point & A, point & B) // returns the square {return (. x-b.x) * (. x-b.x) +. y-b.y) * (. y-b.y);} double round SS (point & A, point & B, point & C) // calculate the X product of a B and a C {Return (B. x-a.x) * (C. y-a.y)-(B. y-a.y) * (C. x-a.x);} int CMP (const void * a, const void * B) {return writable SS (po [0], * (point *) A, * (point *) b)> 1e-8? -1: 1;} int select () {int I, j, k = 1; for (I = 2; I <n; I ++) {If (zero (distinct SS (po [0], po [K], po [I]) {If (DIS (po [0], po [k]) <DIS (po [0], po [I]) po [k] = po [I];} elsepo [++ K] = po [I];} return k + 1;} int Graham (INT num) {int I, j, k = 2; //////////////////////////////////////// // Po [num] = po [0]; // fangbiannum ++; for (I = 3; I <num; I ++) {While (Primary SS (po [k-1], po [K], po [I]) <-EPS) {k --;} po [++ K] = po [I]; // This loop ends, no more !} /* For (I = 0; I <K; I ++) printf ("% lf \ n", po [I]. x, po [I]. y); printf ("\ n"); */return K;} double cal_max_area (INT num) {int I, j, k; double ans, temp; ans =-1; for (I = 0; I <num; I ++) for (j = I + 1; j <num; j ++) for (k = J + 1; k <num; k ++) {temp = Alipay SS (po [I], po [J], po [k]); if (ANS <temp) ans = temp;} return ans;} int main () {int I, J, K, num; point my_temp; while (scanf ("% d", & N )! = EOF) {scanf ("% lf", & po [0]. x, & po [0]. y); temp = po [0]; Pos = 0; for (I = 1; I <n; I ++) {scanf ("% lf ", & po [I]. x, & po [I]. y); If (po [I]. Y <temp. y) temp = po [I], Pos = I;} my_temp = po [0]; po [0] = po [POS]; po [POS] = my_temp; qsort (PO + 1, n-1, sizeof (po [0]), CMP); num = Graham (select (); printf ("%. 2lf \ n ", cal_max_area (Num)/2);} return 0 ;}