Saruman ' s Army (POJ 3069)

Source: Internet
Author: User

There are n points on the line, and the position of point I is XI. Select several of these n points and mark them with a tag. For each point, where the distance is within the area of R must have a marked point (its own labeled point, you can think of its distance of 0 points with a marked point), in the case of satisfying this condition, want to be able to add markers for as few points as possible. How many points should be marked at least?

/** * Starting from the far left, it is necessary to have a marked point in the area within which R is located. The point with this marker is on its right. * So this point should be the farthest from the distance within its R. * After locating its mark point, overwrite all points within the distance of R*/#include<stdio.h>intN,r;inta[ +];voidf () {intcn1=0, t=0, i=0;  while(i<N) {        //find the next starting point         while(T>=a[i] && i<n) i++;//find the second starting point after jumping out of the loopt=a[i]+R; //find the next marker point         while(T>=a[i] && i<n) i++; Ans++; t=a[i-1]+R; } printf ("%d\n", ans);}intMain () { while(SCANF ("%d%d", &n,&r) = =2){         for(intI=0; i<n;i++) scanf ("%d",&A[i]);    f (); }    return 0;} 

Saruman ' s Army (POJ 3069)

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.