https://vjudge.net/problem/POJ-1328

贪心策略选错了恐怕就完了吧。。

一开始单纯地把island排序,然后想从左到右不断更新,其实这是错的。。。因为空中是个圆弧。

后来知道了通过对每个island求雷达范围,将这些范围排序,但是去重策略也没想对。因为有两种情况,都需要更新t值,但是只有一种需要ans++。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
typedef struct{
double x, y;
}Node;
Node node[];
double lengthb(int c, int a)
{
return sqrt(c*c-a*a);
}
bool cmp(const Node a, const Node b)
{
return a.x<b.x;
}
int main()
{
int n, d, a, b, kase=;
while(cin >> n >> d){
if(!n&&!d) break;
int flag=;
for(int i = ; i < n; i++){
cin >> a >> b;
if(d < b) flag=;
else{
double tmp = lengthb(d, b);
node[i].x = a-tmp, node[i].y = a+tmp;
}
}
cout << "Case " << ++kase << ": ";
if(!flag){
cout << "-1" << endl;
continue;
}
sort(node, node+n, cmp);
double t = node[].y;
int ans = ;
for(int i = ; i < n; i++){
if(node[i].y<t||abs(node[i].y-t)<1e-){//这种情况不用ans++,但该雷达的检测范围却因此缩小了
t = node[i].y;
}
else if(t<node[i].x){
t = node[i].y;
ans++;
}
}
cout << ans << endl;
}
return ;
}

poj1328 Radar Installation(贪心 策略要选好)的更多相关文章

  1. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  2. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

  3. [POJ1328]Radar Installation

    [POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...

  4. POJ--1328 Radar Installation(贪心 排序)

    题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...

  5. POJ1328 Radar Installation 【贪心&#183;区间选点】

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

  6. POJ 1328 Radar Installation 贪心 A

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

  7. POJ1328——Radar Installation

    Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...

  8. POJ1328 Radar Installation 解题报告

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

  9. Radar Installation(贪心)

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

随机推荐

  1. web移动端浮层滚动阻止window窗体滚动JS/CSS处理

    CSS代码: .noscroll, .noscroll body { overflow: hidden; } .noscroll body { position: relative; } JS代码: ...

  2. BZOJ1799 self 同类分布 数位dp

    BZOJ1799self 同类分布 去博客园看该题解 题意 给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数. [约束条件]1 ≤ a ≤ b ≤ 10^18 题解 1.所有的位数之和&l ...

  3. springmvc 无法访问静态资源

    没有配置<mvc:resources location="/" mapping="/**"/> <?xml version="1.0 ...

  4. 最终一致性2PC复杂场景,事务报数据库操作超时。

    稀里糊涂的,忘了开启SqlServer的is read committed snapshot on

  5. Kafka Manager

    1.kafka Manager 1.上传压缩包kafka-manager-1.3.3.15.zip到集群 2.解压到/opt/module 3.修改配置文件conf/application.conf ...

  6. C++中全排列算法函数next_permutation的使用方法

    首先,先看对next_permutation函数的解释: http://www.cplusplus.com/reference/algorithm/next_permutation/?kw=next_ ...

  7. java的conllections.sort排序

    https://www.cnblogs.com/yw0219/p/7222108.html?utm_source=itdadao&utm_medium=referral

  8. 4、Qt Project之串口数据传输

    串口数据传输: Step1:串口数据的发送和接收过程,我们需要单独的添加串口的相关模块进去,模块名称叫做serialport,我们需要建立的工程是QMainWindow的基类程序,不是QWidget程 ...

  9. Jenkins使用遇到的问题总结

    学新技能最方便的就是在网上找教程了,我找到一个还不错的易百教程 Jenkins教程 别看教程写了一堆,其实真正用到的没多少.后面的自动化测试,服务器维护啥的,等用到的时候再深入研究吧 No1: 按照教 ...

  10. SpringBoot统一处理异常

    在springboot项目,报错有着默认的提示,这篇文章介绍一下如何统一处理异常. 新建项目,pom文件如下: <?xml version="1.0" encoding=&q ...