Title: http://www.51nod.com/onlineJudge/submitDetail.html#!judgeId=427658
First, the circle on the x-axis to the left starting point in ascending order, and then two points to find the first starting point than the end of the circle to find a large circle (that is, away)
Importjava.util.Arrays;ImportJava.util.Comparator;ImportJava.util.Scanner;classCircle {intX,r,sta,end; Circle (intXintr) { This. x=x; This. r=R; This. sta=x-R; This. end=x+R; } } Public classN1278 { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner cin=NewScanner (system.in); intn=Cin.nextint (); Circle C[]=NewCircle[n]; for(inti=0;i<n;i++) C[i]=NewCircle (Cin.nextint (), Cin.nextint ()); Arrays.sort (c,NewComparator<circle>() { Public intCompare (Circle c1,circle C2) {if(c1.sta>=C2.sta)return1; Else return-1; } }); intSum=0; for(inti=0;i<n-1;i++) { intp=search (i,c,n); if(P!=-1) Sum+=n-p; } System.out.print (sum); } Public Static intSearchintPos,circle c[],intLen) { intKey=c[pos].end,begin=pos+1,last=len-1; while(begin<Last ) { intMid= (begin+last)/2; if(c[mid].sta>key) last=mid; Elsebegin=mid+1; } if(c[begin].sta>key)returnbegin; Else return-1; }}
Want to get away from the circle (sort + binary search)