[Poj1328] radar installation greedy

Source: Internet
Author: User
Tags radar

Question:

There are n coordinates of the island above the X axis, and the radar range is also given. Now we need to put as few radar as possible on the X axis so that the island will be covered with the least number of questions.

Question:

Greedy. Determine the ing range of each island on the X axis (a radar in this range can scan to the Island), then sort by the right border, and then look like a monotonous Queue (of course there is more water ), try to move the radar to the right.

Details:

Note 1:

Radar doesn't have to be on the whole point. Don't be cheated.

NOTE 2:

If the data is incorrect, output-1

1. Some points cannot be scanned

2. Some points are below the X axis

III. D <0

Code:

#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>#define N 1050#define inf 0x3f3f3f3fusing namespace std;int n,d;struct KSD{int x,y;double l,r;bool init(){int temp=d*d-y*y;if(temp<0)return 1;l=x-sqrt(temp);r=x+sqrt(temp);return 0;}bool operator < (const KSD &a)const{return r<a.r;}}s[N];int main(){//freopen("test.in","r",stdin);int i,t=0,flag;while(scanf("%d%d",&n,&d),n||d){printf("Case %d: ",++t);flag=0;if(d<0)flag=1;for(i=1;i<=n;i++){scanf("%d%d",&s[i].x,&s[i].y);if(s[i].y<0||s[i].init())flag=1;}if(flag){puts("-1");continue;}sort(s+1,s+n+1);double now=-999999999.9;int ans=0;for(i=1;i<=n;i++){if(s[i].l<=now)continue;now=s[i].r;ans++;}printf("%d\n",ans);}return 0;}


[Poj1328] radar installation greedy

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.