Poj3069saruman's army

Source: Internet
Author: User

The question is probably like this. It gives you a bunch of numbers. Each number represents a point. It can be understood
Vertices in one-dimensional coordinates, each of which is represented by a number.
We also gave you a number representing the radius.
Give you a rule. When you select a vertex, take it as the center, and the radius can be scanned.
All vertices are marked.
Now you need to mark all vertices and ask you how many times you can mark them.
My practice is greedy. From the leftmost point, count one point. This point just exceeded the leftmost point.
The area that can be scanned as the center, and then centered on this point, then count another point. This point is just
The area that can be scanned by a point that is centered on this page. Select a point that is centered on this page, and so on,
When the last vertex is scanned, the number of marked points is the minimum.
My AC code is as follows:

#include<cstdio>#include<algorithm>using namespace std;int r,num,dot[1010];bool cmp(int a,int b){return a<b;}bool init(){int i;scanf("%d%d",&r,&num);if(r==num&&r==-1)return 0;for(i=0;i<num;i++)scanf("%d",&dot[i]);sort(dot,dot+num,cmp);return 1;}void result(){int i,sum=0,s=0;while(s<num){for(i=s;i<num&&dot[i]<=dot[s]+r;i++);s=i-1;for(i=s;i<num&&dot[i]<=dot[s]+r;i++);s=i;sum++;}printf("%d\n",sum);}int main(){while(init())result();}


 

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.