poj 1328 Radar Installation
题目链接: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的更多相关文章
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- poj 1328 Radar Installation【贪心区间选点】
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- poj 1328 Radar Installation(贪心)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation【贪心】
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- poj 1328 Radar Installation 排序贪心
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56702 Accepted: 12 ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
随机推荐
- Clouda聊天室实践
1.Clouda说明 Clouda是简单,可依赖的实时Javascript框架.对一个想开发移动webapp的开发者来说,可以使用clouda开发框架,实现一个功能和体验与native app齐平的轻 ...
- LayaAir学习笔记
1.Text文本类 var Text=laya.display.Text; Laya.init(620,400); Laya.stage.bgColor="#323232";//设 ...
- [转]MySQL innodb buffer pool
最近在对公司的 MySQL 服务器做性能优化, 一直对 innodb 的内存使用方式不是很清楚, 乘这机会做点总结. 在配置 MySQL 的时候, 一般都会需要设置 innodb_buffer_poo ...
- 170105、MySQL 性能优化的最佳 20+ 条经验
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...
- 卓越精Forsk.Atoll.v3.3.2.10366无线网络
卓越精Forsk.Atoll.v3.3.2.10366无线网络 Atoll是法国 FORSK 公司开发的,是一个全面的.基于Windows的.支持2G.3G.4G多种技术,用户界面 友好的无线网络规划 ...
- HTTP/TCP
转:http://blog.csdn.net/sundacheng1989/article/details/28239711 http://blog.csdn.net/sundacheng1989/a ...
- 我所理解的ECMAScript、DOM、BOM---写给新手们
像很多新手一样,我知道js有三部分组成,即ECMAScript.DOM.BOM三部分组成,ECMAScript是核心解释器.DOM(Document Object Model)是文档对象模型.BOM( ...
- Poj2186Popular Cows
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 31533 Accepted: 12817 De ...
- Spring MVC视图解析器
Spring MVC提供的视图解析器使用ViewResolver进行视图解析,实现浏览器中渲染模型.ViewResolver能够解析JSP.Velocity模板.FreeMarker模板和XSLT等多 ...
- AfxBeginThread中使用updatedata出错
原因:MFC对象不支持多线程操作,不能供多个线程进程使用,所以尽量不要在线程里面更新界面. 解决办法: 1.将工程改为release 2.使用控件来SetWindowText 3.在线程里面发送消息 ...