http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278
Because the center is on the x-axis, each circle is transformed into a segment, sorted by the starting point of the segment, then for each circle from the back to find out the starting point is greater than the current circle to the end of the line segment, the point after the circle will be with the current circle.
Because they are sorted by starting point, they can be solved by two points.
Find yourself in the mess of two-point writing.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <vector>5#include <cstring>6#include <string>7#include <algorithm>8#include <string>9#include <Set>Ten#include <functional> One#include <numeric> A#include <sstream> -#include <stack> -#include <map> the#include <queue> - #pragmaComment (linker, "/stack:102400000,102400000") - #defineCL (arr, Val) memset (arr, Val, sizeof (arr)) - + #definell Long Long - #defineINF 0x7f7f7f7f + #defineLC L,m,rt<<1 A #defineRC M + 1,r,rt<<1|1 at #definePi ACOs (-1.0) - - #defineL (x) (x) << 1 - #defineR (x) (x) << 1 | 1 - #defineMID (L, R) (L + R) >> 1 - #defineMin (x, y) (x) < (y)? (x): (y) in #defineMax (x, y) (x) < (y)? (y): (x) - #defineE (x) (1 << (x)) to #defineIabs (x) (x) < 0? -(x): (x) + #defineOut (x) printf ("%i64d\n", X) - #defineLowbit (x) (x) & (-X) the #defineRead () freopen ("A.txt", "R", stdin) * #defineWrite () freopen ("B.txt", "w", stdout); $ #defineMAXN 1000000000Panax Notoginseng #defineN 2510 - #defineMoD 1000000000 the using namespacestd; + A structnode the { + intx, y; - BOOL operator< (ConstNode A)Const $ { $ if(x==a.x)returny<a.y; - returnx<a.x; - } the}p[50001]; - intN;Wuyi intErfen (intAintb) the { - intl=a,r=n-1, mid=0; Wu while(l<=R) - { AboutMid= (L+R)/2; $ if(p[mid].x>b) r=mid-1; - ElseL=mid+1; - } - if(p[mid].x<=b) mid++; A if(mid>=n)returnN; + Else returnmid; the } - $ intMain () the { the //freopen ("A.txt", "R", stdin); the intb; thescanf"%d",&n); - for(intI=0; i<n;i++) in { thescanf"%d%d",&a,&b); thep[i].x=a-b; Aboutp[i].y=a+b; the } theSort (p,p+n); the //for (int i=0;i<n;i++) + //{ - //printf ("%d%d\n", p[i].x,p[i].y); the //}Bayi intnum=0; the for(intI=0; i<n-1; i++) the { - intX=erfen (i+1, p[i].y); -num+=n-x; the //printf ("%d%d\n", num,x); the the } theprintf"%d\n", num); - return 0; the}
Of course, you can also directly assign p[i].x to another one-dimensional array, and then you can use the Upper_bound to achieve the two-point search.
51nod-1278 the Circle (two minutes)