"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", &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)