poj1328 Radar Installation(贪心 策略要选好)
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(贪心 策略要选好)的更多相关文章
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- poj1328 Radar Installation —— 贪心
题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...
- [POJ1328]Radar Installation
[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ...
- POJ--1328 Radar Installation(贪心 排序)
题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ...
- POJ1328 Radar Installation 【贪心·区间选点】
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- POJ1328——Radar Installation
Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ...
- POJ1328 Radar Installation 解题报告
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
随机推荐
- Atcoder ARC101 Ribbons on Tree
题解: 前面牛客网的那个比赛也有一道容斥+dp 两道感觉都挺不错的 比较容易想到的是 f[i][j]表示枚举到了i点,子树中有j个未匹配 这样的话我们需要枚举儿子中匹配状态 这样是n^2的(这是个经典 ...
- javascript 列表定时滚动效果
HTML结构: <div style="width:200px;height:100px;overflow:hidden;border:1px solid #ddd;margin:20 ...
- 【Android】android:windowSoftInputMode属性详解
activity主窗口与软键盘的交互模式,可以用来避免输入法面板遮挡问题,Android1.5后的一个新特性. 这个属性能影响两件事情: [一]当有焦点产生时,软键盘是隐藏还是显示 [二]是否减少活动 ...
- SQL Server生成数据库的数据字典存储过程
use fpErp --指定要生成数据字典的数据库 go SELECT 表名=case when a.colorder=1 then d.name else '' end, 表说明=case whe ...
- Python_xml
xml: 可扩展标记语言,用来标记数据,定义数据类型,主要用来传输和存储数据(和json差不多,不同语言或程序之间进行数据交换的协议) ET(xml.etree.ElementTree)中的几个类: ...
- Ubuntu学习
一. Ubuntu简介 Ubuntu(乌班图)是一个基于Debian的以桌面应用为主的Linux操作系统,据说其名称来自非洲南部祖鲁语或科萨语的“ubuntu”一词,意思是“人性”.“我的存在是因为大 ...
- appium---第四个脚本,进入app,有权限弹窗的方法
1.以淘宝为例:进入首页,会弹出好几个权限弹窗 无法使用id定位 用xpath定位
- create-react-app项目添加less配置
使用create-react-app 创建的项目默认不支持less,以下增加less配置的步骤 暴露配置文件 create-react-app生成的项目文,看不到webpack相关的配置文件,需要先暴 ...
- 基于netty的websocket例子
nettyServer package com.atguigu.netty.websocket; import javax.annotation.PostConstruct; import org.s ...
- myBatis之Clob & Blob
1. 表结构 1.1 在Mysql中的数据类型,longblob --> blob, longtext --> clob 2. 配置文件, 请参考 myBatis之入门示例 3. L ...