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. Flink运行在yarn上

    在一个企业中,为了最大化的利用集群资源,一般都会在一个集群中同时运行多种类型的 Workload.因此 Flink 也支持在 Yarn 上面运行: flink on yarn的前提是:hdfs.yar ...

  2. Python题目练习(一)

    1.使用while循环输入 1 2 3 4 5 6  8 9 10 i = 1 while i <=10 : if i != 7: print(i) else: print(' ') i += ...

  3. BZOJ3926 [Zjoi2015]诸神眷顾的幻想乡 字符串 SAM

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ3926.html 题目传送门 - BZOJ3926 题意 给定一个有 $n$ 个节点,最多只有 $20$ ...

  4. CF552 E. Two Teams

    题意:给出一串n个数   为1-n的乱序 一共有两个教练   教练一的队伍是1队  二是二队 教练一选择 当前队列中剩余人数的最大序号   将其和左边k个人 和右边k个人 变为一队 如此反复直到所有人 ...

  5. P1087 FBI树 二叉树

    题目描述 我们可以把由“00”和“11”组成的字符串分为三类:全“00”串称为BB串,全“11”串称为I串,既含“00”又含“11”的串则称为F串. FBIFBI树是一种二叉树,它的结点类型也包括FF ...

  6. Python3 序列解包

    转载自:https://blog.csdn.net/yilovexing/article/details/80576788 序列解包是 Python 3.0 之后才有的语法 什么是序列解包呢?先看一个 ...

  7. Linux下C语言的进程控制编程

    代码: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/ty ...

  8. miniui中可以设置是否让页面进行分页 <div id="datagrid1" class="mini-datagrid" style="width:100%" allowAlternating="true" showpager="true"/> 就是设置showpager属性为true

    <div id="datagrid1" class="mini-datagrid" style="width:100%" allowA ...

  9. JAVA程序的基本结构

    java程序(类)其实是一个静态方法库,或者是定义了一个数据类型.所以会遵循7种语法:     1.原始数据类型:             ---整型:byte.short.int.long ---浮 ...

  10. 最短路(Floyd)-hdu1317

    题目链接:https://vjudge.net/problem/HDU-1317 题目描述: 题意:玩家起始有100个能量点,刚开始在起始房间中,每个房间外有一条单向的路径通往其他房间(一个房间可能通 ...