HDU 5784 How many triangles polar angle sort calculation acute angle obtuse angles

Source: Internet
Author: User

The main topic: give you n points, calculate how many acute triangle.

Number of acute triangle = (number of acute angles in figure-Blunt right angle number)/3

There are several blunt right angles, acute angles in the calculation diagram. Enumerates the vertices of a corner, and then enumerates the edges that the vertex leads to, which can be represented by a vector. These vectors are sorted in polar order, enumeration of the starting edge, the method of the ruler, calculated with the edge of a sharp angle, blunt right side of the bar number. Statistics, and finally output the answer.

#include <bits/stdc++.h> using namespace std;
Const Double Pi=acos (-1);
const int maxn=2000+5;
const double eps=1e-12;

typedef long Long LL;
    struct point{double x, y;
    Double angle;
    BOOL operator< (Point ZZ) const{return angle<zz.angle;
}}P[MAXN];

Point A[maxn*2];
    int main () {int n;
        while (~SCANF ("%d", &n)) {int x, y;
        for (int i=0;i<n;i++) scanf ("%d%d", &x,&y), p[i].x=x,p[i].y=y;
        ll Ans1=0,ans2=0;
            for (int i=0;i<n;i++) {int siz=0;
                for (int j=0;j<n;j++) {if (i==j) continue;
                a[siz]=point{p[j].x-p[i].x,p[j].y-p[i].y,0};
            A[siz].angle=atan2 (a[siz].y,a[siz].x); siz++;
            } sort (A,a+siz);
            for (int j=siz;j<2*siz;j++) {a[j].angle=a[j-siz].angle+2*pi;
            } int s=1,t=1,len=1; for (int j=0;j<siz;j++) {while (a[t].angle-a[j].angle<p i&&t<2*siz) t++;
                while (A[s].angle-a[j].angle<0.5*pi&&s<2*siz) s++;
                while (A[len].angle-a[j].angle<eps&&len<2*siz) len++;
                Ans1=ans1+t-s;
            Ans2=ans2+s-len;
    }} printf ("%i64d\n", (ans2-ans1*2)/3);
} 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.