poj 1328 贪心
/*
贪心....
处理处每个点按照最大距离在x轴上的映射
然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现
我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端点
若下一条与之无交点 则再按一个雷达 若完全覆盖 贪心的 我们把雷达移动到下一条的右端点
这样这个雷达就又多覆盖了一个岛
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 1010
using namespace std;
int n,ans,cas;
double d,x,y;
struct node
{
double l,r;
}p[maxn];
int cmp(const node &a,const node &b)
{
if(a.l==b.l)return a.r<b.r;
return a.l<b.l;
}
int main()
{
while()
{
ans=;int falg=;
scanf("%d%lf",&n,&d);
if(n==&&d==)break;
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&x,&y);
if(y>d)falg=;
p[i].l=x-sqrt(d*d-y*y);
p[i].r=x+sqrt(d*d-y*y);
}
if(falg){printf("Case %d: -1\n",++cas);continue;
sort(p+,p++n,cmp);
double t=p[].r;
for(int i=;i<=n;i++)
{
if(p[i].l>t)
{
ans++;t=p[i].r;continue;
}
if(p[i].r<=t)
{
t=p[i].r;continue;
}
if(p[i].r>t)continue;
}
printf("Case %d: %d\n",++cas,ans);
}
return ;
}
poj 1328 贪心的更多相关文章
- poj 1328贪心
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- 贪心 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【贪心】
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- 贪心问题:区间覆盖 POJ 1328 Rader Installation
题目:http://poj.org/problem?id=1328 题意:给定海岛个数,雷达半径,输入各个海岛坐标,求能覆盖所有海岛的最少雷达数 题解: 1. 贪心的区间覆盖问题,尽量让每个雷达覆盖更 ...
- 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(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- poj 1328 Radar Installatio【贪心】
题目地址:http://poj.org/problem?id=1328 Sample Input 3 2 1 2 -3 1 2 1 1 2 0 2 0 0 Sample Output Case 1: ...
随机推荐
- 在linux下将当前目录文件全部小写含目录名
ls | sed -n '/[A-Z]/s/.*/mv & \L&/e' 公司以前用的windows server 服务器 文件大小写都一样. 新迁移到centos 服务器上,发现 ...
- C语言基础学习基本数据类型-字符专属的输入输出函数
可以使用%c说明符以及scanf()和printf()函数来输入输出字符.现在我们将学习专门为面向字符而设计的一对函数:getchar()和putchar().getchar()函数没有参数,它返回来 ...
- Python 网路编程读书笔记x UDP
UDP 协议基础 在IP网络层,所有的数据包会向一个指定的主机传输 Source IP -> Destination IP 但是两台机器之间可能有许多独立的应用需要进行通信,因此为了区分不同的 ...
- 栈的顺序存储方式的C语言实现
/* 编译器:Dev-c++ 5.4.0 文件名:stack.cpp 代码版本号:1.0 时间:2015-10-10 20:08:54 */ #include <stdio.h> #inc ...
- 栈的讲解 和 栈的生长方向 源代码技巧分析,简直没SEI 啦
函数的局部变量,都是存放在"栈"里面,栈的英文是:STACK.STACK的大小,我们可以在stm32的启动文件里面设置,以战舰stm32开发板为例,在startup_stm32f1 ...
- UVA - 1614 Hell on the Market(贪心)
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Descript ...
- 12100 Printer Queue(优先队列)
12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...
- 《FPGA零基础入门到精通视频教程》-第001b讲软件的破解
高清视频和配套讲义这里下载 http://www.fpgaw.com/thread-68128-1-1.html 优酷视频地址,不是很清楚
- 前端工程之模块化(来自百度FEX)
模块化 是一种处理复杂系统分解成为更好的可管理模块的方式,它可以把系统代码划分为一系列职责单一,高度解耦且可替换的模块,系统中某一部分的变化将如何影响其它部分就会变得显而易见,系统的可维护性更加简单易 ...
- JMS 问题java.lang.NoClassDefFoundError: weblogic/security/acl/UserInfo
run: Exception in thread "main" java.lang.NoClassDefFoundError: weblogic/security/acl/User ...