POJ 1328 Radar Installation

Radar Installation
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 36207 Accepted: 8039

Description

Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.

We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

Figure A Sample Input of Radar Installations


Input

The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.

The input is terminated by a line containing pair of zeros

Output

For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.

Sample Input

3 2
1 2
-3 1
2 1

1 2
0 2

0 0

Sample Output

Case 1: 2
Case 2: 1

Source

[Submit] [Go Back] [Status] [Discuss]

Home Page Go Back To top
这题目在知道贪心的情况下仍然错了很多次,看了看解题报告才知道自己的贪心策略有问题,可以求覆盖每个岛的的区间,对区间按左端点进行排序,这样这个问题就转化成了区间覆盖问题

#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
class num
{
    public:
    double x1,x2;
}a[10000];
int cmp(const void *e,const void *f)
{
    num *p1=(num *)e;
    num *p2=(num *)f;
    if(p1->x1>p2->x1)
    {
        return 1;
    }else if(p1->x1<p2->x1)
    {
        return -1;
    }else
    {
        return 0;
    }
}
int main()
{
    int i,j,n,m,s,t,x,y;
    int r,k;
    double b,c,right;
    t=1;
    while(cin>>n>>r)
    {
        if(!n&&!n)
        {
            break;
        }
        k=0;
        for(i=0;i<=n-1;i++)
        {
            cin>>x>>y;
            if(y>r)
            {
                k=1;
            }
            if(k==0)
            {
               b=sqrt((double)(r*r-y*y));
               a[i].x1=(double)x-b;
               a[i].x2=(double)x+b;
            }
        }
        if(k==1)
        {
            cout<<"Case "<<t<<":"<<" "<<"-1"<<endl;
            t++;
            continue;
        }
        qsort(a,n,sizeof(a[0]),cmp);
        s=1;
        right=a[0].x2;
        for(i=1;i<=n-1;i++)
        {
            if(a[i].x1-right>0)
            {
                s+=1;
                right=a[i].x2;
            }else
            {
                if(a[i].x2-right<0)
                {
                    right=a[i].x2;
                }
            }
        }
        cout<<"Case "<<t<<":"<<" "<<s<<endl;
        t++;
    }
    return 0;
}


 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
未来社区的建设背景和需求分析指出,随着智能经济、大数据、人工智能、物联网、区块链、云计算等技术的发展,社区服务正朝着数字化、智能化转型。社区服务渠道由分散向统一融合转变,服务内容由通用庞杂向个性化、服务导向转变。未来社区将构建数字化生态,实现数据在线、组织在线、服务在线、产品智能和决策智能,赋能企业创新,同时注重人才培养和科研平台建设。 规划设计方面,未来社区将基于居民需求,打造以服务为中心的社区管理模式。通过统一的服务平台和应用,实现服务内容的整合和优化,提供灵活多样的服务方式,如推送式、订阅式、热点式等。社区将构建数据与应用的良性循环,提高服务效率,同时注重生态优美、绿色低碳、社会和谐,以实现幸福民生和产业发展。 建设运营上,未来社区强调科学规划、以人为本,创新引领、重点突破,统筹推进、整体提升。通过实施院落+社团自治工程,转变政府职能,深化社区自治法制化、信息化,解决社区治理中的重点问题。目标是培养有活力的社会组织,提高社区居民参与度和满意度,实现社区治理服务的制度机制创新。 未来社区的数字化解决方案包括信息发布系统、服务系统和管理系统。信息发布系统涵盖公共服务类和社会化服务类信息,提供政策宣传、家政服务、健康医疗咨询等功能。服务系统功能需求包括办事指南、公共服务、社区工作参与互动等,旨在提高社区服务能力。管理系统功能需求则涉及院落管理、社团管理、社工队伍管理等,以实现社区治理的现代化。 最后,未来社区建设注重整合政府、社会组织、企业等多方资源,以提高社区服务的效率和质量。通过建立社区管理服务综合信息平台,提供社区公共服务、社区社会组织管理服务和社区便民服务,实现管理精简、高效、透明,服务快速、便捷。同时,通过培育和发展社区协会、社团等组织,激发社会化组织活力,为居民提供综合性的咨询和服务,促进社区的和谐发展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值