Title Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278
This problem takes two poses. The first converts a circle-separated model into a line segment and a line segment, and then there is the step that modifies the loop variable. Achieves the effect of reducing time complexity, but only reduces the coefficient and does not decrease the number of times =
#include <stdio.h>#include<string.h>#include<iostream>#include<algorithm>#defineINF 10000000using namespacestd;structnode{intl,r;};BOOLCMP (node A,node b) {if(a.l==B.L)returna.r<B.R; returna.l<B.L;} Node a[50000];intMain () {intN,c,r; scanf ("%d",&N); for(intI=0; i<n;i++) {scanf ("%d%d",&c,&R); A[I].L=c-R; A[I].R=c+R; } sort (A,a+n,cmp); /*for (int i=0;i<n;i++) {printf ("%d%d\n", A[I].L,A[I].R); }*/ intans=0; intmin; inti,j; for(i=0; i<n;i++) { for(j=i+ -; j<n;j+= -)//search for disjoint segments within 100 step { if(a[j].l>A[I].R) Break; } if(j>n) J=n;//It's going to take this step when it's greater than n for(intk=j-1; k>=0&&k>j-101; k--)//and then scan within 100 . { if(a[k].l<=A[I].R) {ans+=n-(k +1); Break; }}} printf ("%d\n", ans); return 0;}
1278 the circle of the absent (51nod)