The plane gives you n (no more than 2000) points and asks how many of the rt triangles You can make up the area between [A and b].
Enumerate each point as a right-angled vertex, sort on other point angles, sort by length in the same direction, and then enumerate each vector in turn, with its corresponding right-angled edge being monotonous, can be made with a pointer, and then the bands of those vectors in the same direction can be drawn (this code seems a bit problematic, may degenerate, It is advisable to determine the RR after a ll and do not repeat in one direction. It's better if you change it to two, and the complexity doesn't degenerate. Then through the two can get a so that the area in [a, b] between what (in fact, this is also monotonous, as if there is no need for two points, but the two points do not affect).
Hint: Polar sorting by discussing the quadrant and cross product, you can avoid using atan2 to create accuracy errors. Atan2 seems to be able to deal with coordinates within thousands of of the situation.
O (N^2LOGN)
#include <cstdio> #include <algorithm>using namespace std;typedef long long ll;ll ans;struct point{ll x,y;int Xx;ll l; Point () {}point (const ll &x,const ll &y) {this->x=x;this->y=y;} void Read () {scanf ("%lld%lld", &x,&y);} ll Leng2 () {return x*x+y*y;}} A[2005],p[4005];typedef Point Vector; Vector operator-(const point &a,const point &b) {return Vector (A.X-B.X,A.Y-B.Y);} BOOL CMP (const point &a,const point &b) {if (a.xx!=b.xx) {return a.xx<b.xx;} if (a.x*b.y! = a.y*b.x) {return a.x*b.y > a.y*b.x;} return A.L<B.L;} ll dot (const vector &a,const vector &b) {return a.x*b.x+a.y*b.y;} ll Abs (const ll &x) {return x<0? (-X): x;} ll area (const vector &a,const vector &b) {return Abs (a.x*b.y-a.y*b.x);} ll cross (const vector &a,const vector &b) {return a.x*b.y-a.y*b.x;} ll A,b;int N,e;int Main () {//freopen ("j.in", "R", stdin);//freopen ("J.out", "w", stdout); scanf ("%d%lld%lld", &n, &A,&B); for (int i=1;i<=n;++i) {a[i].read ();} For (inT i=1;i<=n;++i) {e=0;for (int j=1;j<=n;++j) {if (j!=i) {p[++e]=a[j]-a[i];if (p[e].x>0 && p[e].y>=0) { P[e].xx=1;} else if (p[e].x<=0 && p[e].y>0) {p[e].xx=2;} else if (p[e].x<0 && p[e].y<=0) {p[e].xx=3;} else{p[e].xx=4;} P[e].l=p[e].leng2 ();}} Sort (p+1,p+e+1,cmp); for (int j=e+1;j<=2*e;++j) {p[j]=p[j-e];} E<<=1;int ll=1;for (int j=1;j<=e/2;++j) {while (dot (p[ll],p[j]) >0 && Cross (p[ll],p[j]) <=0 & & LL<J+E/2) {++ll;} if (dot (p[ll],p[j])!=0 | | Cross (P[ll],p[j]) >0) {continue;} int Rr=ll;while (Cross (P[rr],p[ll]) ==0 && dot (p[rr],p[ll]) >0) {++RR;} if (RR>LL) {if (area (p[ll],p[j)) <=2ll*a-1ll) {int L=ll,r=rr-1;while (l<r) {int mid= (l+r+1>>1), if (area (p [Mid],p[j]) <=2ll*a-1ll) {L=mid;} Else{r=mid-1;}} ans-= (LL) (l-ll+1);} if (area (p[ll],p[j)) <=2ll*b) {int L=ll,r=rr-1;while (l<r) {int mid= (l+r+1>>1), if (area (P[mid],p[j]) <= 2LL*B) {L=mid;} Else{r=mid-1;}} ans+= (LL) (l-ll+1);}}} printf ("%lld\n", ans); return 0;}
Compute geometry "polar sort" "dichotomy" Petrozavodsk Summer Training Camp Day 6:warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, Problem J. Triangles