Maximum triangle of HDU 2022 (maximum triangle in a set)

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.