BAPC2014 C&&hunnu11583:citadel Construction (geometry)

Source: Internet
Author: User

Test instructions

Give a series of points that require searching for up to 4 points to make up a polygon of the largest area


Ideas:

Obviously there are only two cases, either a triangle or a quadrilateral.

First of all, it is not difficult to think of the first to find out the most out of the point, is actually looking for convex bag

But there is no convex hull, so what to do?

We know that when the AB is multiplied with the AC vector to get ab*ac>=0, we can know that all of these conditions are fixed in the clockwise direction, so we can use this to find all the outer points.

After we get these points, we can figure out the answers.


#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <math.h> #include <bitset># Include <algorithm> #include <climits>using namespace std; #define LS 2*i#define rs 2*i+1#define up (i,x,y) for (i=x;i<=y;i++) #define DOWN (i,x,y) for (i=x;i>=y;i--) #define MEM (a,x) memset (A,x,sizeof (a)) #define W (a) while (a) #define GCD (A, B) __gcd (A, b) #define LL long long#define ULL unsigned long long#define N 1005#define INF 0x3f3f3f3f#define E  XP 1e-8#define rank rank1const int mod = 1000000007;struct point{int x, y;} a[n],s[n];int t,n;int ads (int a) {return A&LT;0?-A:A;} int mult (point a,point b,point c) {return (a.x-c.x) * (B.Y-C.Y)-(b.x-c.x) * (A.Y-C.Y);}    int CMP (point A,point B) {if (A.Y==B.Y) return a.x<b.x; return A.Y&LT;B.Y;}    int Set1 (point a[],int n,point s[]) {int i,j,k;    int top = 1;    Sort (a,a+n,cmp); if (n==0) RETUrn 0;    S[0] = a[0];    if (n==1) return 1;    S[1] = a[1];    if (n==2) return 2;    S[2] = a[2];            for (i = 2; i<n; i++)//First Look for the right outer layer {while (Top&&mult (a[i],s[top],s[top-1]) >=0)//new incoming in the clockwise direction, can replace the stored in the stack        top--;    S[++top] = A[i];    } int len = top;    S[++top] = a[n-2];         for (i = n-3; i>=0; i--)//Find the LEFT outer {while (Top!=len&&mult (a[i],s[top],s[top-1]) >=0) top--;    S[++top] = A[i]; } return top;}    void Solve () {int i,j,k,cnt,area;    for (int i=0; i<n; i++) scanf ("%d%d", &a[i].x,&a[i].y);    CNT = Set1 (a,n,s);    if (cnt<3) {printf ("0\n");        } else if (cnt==3) {area = Mult (S[2],s[1],s[0]);        Area = Ads (area);        if (area%2) printf ("%d.5\n", AREA/2);    else printf ("%d\n", AREA/2);        } else {area=-inf;        S[CNT] = s[0];            for (i = 0; i<cnt; i++) {int L = I,r = i+2; for (j = i+2; j<cnt; j + +)//with I,jFor quadrilateral Diagonal, both sides of the loop ensure that two triangles do not intersect to calculate the maximum area {while (ABS (Mult (s[l+1],s[j],s[i)) >abs (Mult (S[l],s[j],s[i]))) L                = (l+1)%cnt;                int S1 = ABS (Mult (s[l],s[j],s[i));                while (ABS (Mult (s[r+1],s[j],s[i))) >abs (Mult (S[r],s[j],s[i]))) R = (r+1)%cnt;                int s2 = ABS (Mult (s[r],s[j],s[i));            Area = max (AREA,S1+S2);        }} if (area%2) printf ("%d.5\n", AREA/2);    else printf ("%d\n", AREA/2);    }}int Main () {scanf ("%d", &t);        while (t--) {scanf ("%d", &n);    Solve (); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

BAPC2014 C&&hunnu11583:citadel Construction (geometry)

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.