题目链接:http://poj.org/problem?id=1328

题意:给出海上有n个小岛的坐标,求发出的信号可以覆盖全部小岛的最少的雷达个数。雷达发射信号是以雷达为圆心,d为半径的圆,雷达都在x轴上。

分析:1.刚开始就知道这道题要用贪心做,但是一下子想不出该如何贪心。然后图图画画后发现只要求出可以覆盖每一个小岛的雷达的区间范围即可,然后可以转化为贪心区间求点问题。正好今天在复习贪心思想时在紫书上看到这个例子啦~(紫书P233)

2.贪心区间求点,就是排序后尽量选择重合区间多的地方选择放点。

3.但是还是WA了一次,因为标记数字is[]没有初始化...T^T题目有多组输入,单独测样例时答案都对,一起测多组的时候就错,还好后来还是发现了这个错误。

贴代码:

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct QuJian
{
double l,r;
};
int cmp(QuJian a,QuJian b)
{
if(a.r==b.r)
return a.l>b.l;
return a.r<b.r;
}
QuJian qu[];
int is[];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,d;
int t=;
while(scanf("%d%d",&n,&d)==)
{
if(!n&&!d)
break;
int x,y;
memset(is,,sizeof(is));
double tp;
bool flag=;
for(int i=;i<n;i++)
{
scanf("%d%d",&x,&y);
tp=d*d-y*y;
if(tp<||d<)
{
flag=;
continue;
}
if(flag)
{
qu[i].l=x-sqrt(tp);
qu[i].r=x+sqrt(tp);
}
}
if(!flag)
printf("Case %d: -1\n",++t);
else
{
int ans=;
sort(qu,qu+n,cmp);
//for(int i=0;i<n;i++)
// cout<<qu[i].l<<" "<<qu[i].r<<endl;
for(int i=;i<n;i++)
{
if(is[i])
continue;
ans+=;
for(int j=i+;j<n;j++)
{
if(qu[j].l<=qu[i].r)
is[j]=;
}
}
printf("Case %d: %d\n",++t,ans);
}
}
return ;
}

poj 1328 Radar Installation的更多相关文章

  1. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  2. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  3. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  4. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  5. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  6. poj 1328 Radar Installation(贪心)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  7. POJ 1328 Radar Installation【贪心】

    POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...

  8. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  9. poj 1328 Radar Installation 排序贪心

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56702   Accepted: 12 ...

  10. POJ 1328 Radar Installation(很新颖的贪心,区间贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 106491   Accepted: 2 ...

随机推荐

  1. 在Eclipse下搭建Android开发环境教程

    我们昨天向各位介绍了<在NetBeans上搭建Android SDK环境>,前不久也介绍过<在MyEclipse 8.6上搭建Android开发环境>, 都受到了读者的欢迎.但 ...

  2. Centos7下Etcd集群搭建

    一.简介 "A highly-available key value store for shared configuration and service discovery." ...

  3. QT网络编程

    bool QAbstractSocket::waitForReadyRead(int msecs = 30000) bool QAbstractSocket::waitForDisconnected( ...

  4. GreenDao关系建表

    关系 在greenDAO,实体涉及使用一对一或一对多的关系.例如,如果要模拟一个1:greenDAOñ关系,你将有一个一对一和一对多的关系.但是,请注意,一对一和一对多的关系不是相互连接,所以你必须同 ...

  5. Android 逐帧动画

    原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...

  6. ORACLE表的恢复

         对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的.一般步骤有: 1.从flash back里查询被删除的表     select * from ...

  7. #region Json转DataTable

    #region  Json转DataTable        private DataTable Json2Dtb(string json)        {            JavaScrip ...

  8. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  9. angular学习之关于ng-class详解

    1,定义和用法 ng-class 指令用于给 HTML 元素动态绑定一个或多个 CSS 类. ng-class 指令的值可以是字符串,对象,或一个数组. 如果是字符串,多个类名使用空格分隔. 如果是对 ...

  10. 关于xmpp协议发送消息,登录认证SSL报错的问题

    Q:错误描述如下 Traceback(most recent call last): File"/tails-share/features/scripts/otr-bot.py", ...