1278 the circle of the absent (51nod)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.