Bzoj 1132 [Poi2008]tro (Extreme angle sort)

Source: Internet
Author: User

"Topic link" http://www.lydsy.com/JudgeOnline/problem.php?id=1132

"The main topic"

There are n points on a plane. Find the area and (n<=3000) of all triangles with these N points as vertices

Exercises

We found that the direct enumeration of three point computations would cause a large portion of the cross-product repetition to be computed,
So we enumerate I, calculate the suffix of PJ and pi spreads, and we find that for fixed edge ij,
Its contribution to the subsequent enumerator is the PJ-PI and the spread suffix and the cross product.
So we have a polar order for each of the subsequent data for each I, and O (n) Calculates all the answer contributions related to I.

#include <algorithm> #include <cstdio> #include <cmath> using namespace std;typedef long Long ll;struct    point{int x, y; int index;    Point () {}, point (int x1,int y1) {x=x1;y=y1;}     Point operator + (const point &b) Const{return Point (X+B.X,Y+B.Y);     Point operator-(const point &b) Const{return Point (X-B.X,Y-B.Y); int operator * (const point &b) Const{return x*b.x+y*b.y;}/dot product LL operator ^ (Const point &b) Const{return (LL) x*b . Y (LL) y*b.x;} Cross product};d ouble Dist (point A,point b) {return sqrt ((a) * (a));} int POS;    Point P[3010];bool CMP (point A,point b) {LL tmp= (A-p[pos]) ^ (B-p[pos]);    if (tmp==0) return dist (p[pos],a) <dist (p[pos],b);    else if (tmp<0) return false; else return true;} int N;int Main () {while (~SCANF ("%d", &n)} {for (int i=1;i<=n;i++) {scanf ("%d%d", &AMP;P[I].X,&A         MP;P[I].Y);         }ll ans=pos=0;         Sort (p+1,p+n+1,cmp);       for (int i=1;i<=n-2;i++) {p[0].x=p[0].y=0;pos++;      Sort (p+i+1,p+n+1,cmp);             for (int j=i+1;j<=n;j++) p[0]=p[0]+ (P[j]-p[i]);                 for (int j=i+1;j<=n;j++) {p[0]=p[0]-(p[j]-p[i]);             ans+= (P[j]-p[i]) ^p[0];         }}if (ans&1) printf ("%lld.5\n", ans>>1);    else printf ("%lld.0\n", ans>>1); }return 0;}

Bzoj 1132 [Poi2008]tro (polar sort)

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.