poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328
题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地。在海上有n个小岛,每个小岛看做一个点。然后在x轴上有雷达,雷达能覆盖的范围为d,问至少需要多少个雷达能监测到多有的小岛。
思路:从左到右把每个小岛的放置雷达的区间求出,按结束点排序,从左至右看,当发现下一个区间的起始点大于前面所有区间的最小结束点的时候,答案加一。
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h> using namespace std;
struct node
{
double a,b;
}area[]; int cmp(const void *a,const void *b)
{
return (*(node *)a).b>(*(node *)b).b?:-;
} int main()
{
int n,i,sum,f,h=;
double x,y,d,e;
while(~scanf("%d%lf",&n,&d)&&(n!=||d!=))
{
f=; sum=;
for(i=; i<n; i++)
{
scanf("%lf%lf",&x,&y);
area[i].a=x-sqrt(d*d-y*y);
area[i].b=x+sqrt(d*d-y*y);
if(y<)
y=-y;
if(y>d)
f=;
} if(f)
printf("Case %d: -1\n",h); else
{
qsort(area,n,sizeof(area[]),cmp);
e=area[].b;
for(i=; i<n; i++)
{
if(area[i].a>e)
{
sum++;
e=area[i].b;
}
}
printf("Case %d: %d\n",h,sum);
}
h++;
}
return ;
}
poj 1328 Radar Installation(贪心)的更多相关文章
- 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(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- 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 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- python staticmethod classmethod
http://www.cnblogs.com/chenzehe/archive/2010/09/01/1814639.html classmethod:类方法staticmethod:静态方法 在py ...
- php 字母大小写转换的函数
分享下,在php编程中,将字母大小写进行转换的常用函数. 1.将字符串转换成小写strtolower(): 该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串 2.将字符转成大 ...
- closest()一个在评论里很有用的函数
实例 本例演示如何通过 closest() 完成事件委托.当被最接近的列表元素或其子后代元素被点击时,会切换黄色背景: $( document ).bind("click", fu ...
- Oracle外部表的使用
外部表可以像其它表一样,用select语句作查询.但不能做DML操作,不能建index,不接受约束.这是因为它不是以段的形式存于数据库中,只是以数据字典构造存在,指向一个或多个操作系统文件. 外部表的 ...
- 【NHibernate】HQL入门
在NHibernate 中 HQL 可以帮我们转成最终依赖数据库的查询脚本: 语法也甚是强大,适配主流数据库, HQL不支持union,要想取多个表数据可以做两次单独查询. IQuery query ...
- sql查找最小缺失值与重用被删除的键(转载)
转载自:http://blog.csdn.net/yanghua_kobe/article/details/6262550 在数据处理时,我们经常会使用一些“自增”的插入方式来处理数据.比如学生学号: ...
- 解决.net定时器在iis7上不执行问题
今天第一次在博客园发帖,以前一直在潜水,在这里也是学了不少东西.感谢各位园友 废话不多说,这也是我工作中遇到的问题: protected void Application_Start(object s ...
- EXTJS 3.0 资料 控件之 GridPanel属性与方法大全
1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模式 autoExpandColumn:自动充 ...
- 【BZOJ 1491】 [NOI2007]社交网络
Description Input Output 输出文件包括n 行,每行一个实数,精确到小数点后3 位.第i 行的实数表 示结点i 在社交网络中的重要程度. Sample Input 4 4 1 2 ...
- html template
https://wrapbootstrap.com/tag/single-page http://themeforest.net/ https://wrapbootstrap.com/themes h ...