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. ASP.NET Core 2.0 新功能汇总

    前言 ASP.NET Core 的变化和发展速度是飞快的,当你发现你还没有掌握 ASP.NET Core 1.0 的时候, 2.0 已经快要发布了,目前 2.0 处于 Preview 1 版本,意味着 ...

  2. python全栈开发day75-用户注册页面ajax实现,用户头像上传、预览、展示

    一.昨日内容回顾 1. 内容回顾 1. BBS项目登录 1. 登录用form组件和auth模块 1. form组件做校验很方便 2. auth模块 - authenticate(username=xx ...

  3. Javascript转义字符串中的特殊字符处理

    Web应用系统中,客户端发送请求到服务器,请求中的字符串参数,在被序列化成json过程中有些特殊字符会被空格代, 导致传递到服务器端再解析的时候,原本的输入参数就会被改变. 目前遇到的特殊字符有加号( ...

  4. Python_copy_深浅拷贝

    对于数字和字符串来说,无论是‘’赋值‘’还是‘’深拷贝‘’还是‘’浅拷贝‘’都是指向的同一个地址 深浅拷贝是copy类下的方法,创建方式为 import copy copy.copy() #浅拷贝 c ...

  5. net core体系-2继续认识net core

    认识net core,net core到底啥?从哪说起呢?我想作为开发的码农,web项目不陌生吧,那就从对应的.net web 对应的net core Web Application项目开始吧. 下面 ...

  6. plink命令

    用plink远程登陆link主机执行脚本,但是无法执行sudo命令 完成后自己关闭 plink   -l  root   192.168.1.21  df -h plink.exe  -ssh  -p ...

  7. ELK使用3-Logstash

    一.命令行输入输出操作 1.命令行输出: /application/elk/logstash/bin/logstash -e 'input { stdin{} } output { stdout{} ...

  8. ZJOI2018 胖 二分 ST表

    原文链接https://www.cnblogs.com/zhouzhendong/p/ZJOI2018Day2T2.html 题目传送门 - BZOJ5308 题目传送门 - LOJ2529 题目传送 ...

  9. datatable 转list ,list转datatable

    方法一:  public static IList<T> ConvertToModel(DataTable dt)             {                // 定义集合 ...

  10. C#中的 Stream

    目录: 什么是Stream? 什么是字节序列? Stream的构造函数 Stream的重要属性及方法 Stream的示例 Stream异步读写 Stream 和其子类的类图 本章总结 什么是Strea ...