贪心

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct Radar {
double start,end;
} radar[];
bool cmp(Radar a,Radar b) {
return a.start<b.start;
}
int main() {
int n,d,x,y,m,num,flag;
double l,r;
m = ;
while(scanf("%d%d",&n,&d)) {
if(!n && !d) //如果为0
break;
flag = true;
for(int i = ; i < n; i++) {
scanf("%d%d",&x,&y);
if(y > d)
flag = false;
radar[i].start = x - sqrt(d * d - y * y); //勾股定理
radar[i].end = x + sqrt(d * d - y * y); //区间覆盖范围
}
if(!flag) {
printf("Case %d: -1\n",m++);
continue;
}
sort(radar,radar + n,cmp); //排序 n为岛屿数目
num = ,l = radar[].start,r = radar[].end;//l和r是double l为最左端的区间的左端 r为右端
for(int i = ; i < n; i++) {
if(radar[i].start >= l && radar[i].end <= r) { // 某两块区间存在包含关系
l = radar[i].start;
r = radar[i].end;
} else if(radar[i].start <= r && radar[i].end >= r) //某两个区间交叉
l = radar[i].start;
else if(radar[i].start > r) { //两个区间没有交集
l = radar[i].start;
r = radar[i].end;
num++;
}
}
printf("Case %d: %d\n",m++,num);
}
return ;
}

Virtual Judge POJ 1328 Radar Installation的更多相关文章

  1. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  2. POJ 1328 Radar Installation 贪心 A

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

  3. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  4. poj 1328 Radar Installation(nyoj 287 Radar):贪心

    点击打开链接 Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43490   Accep ...

  5. poj 1328 Radar Installation【贪心区间选点】

    Radar Installation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  6. poj 1328 Radar Installation(贪心)

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

  7. POJ 1328 Radar Installation【贪心】

    POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...

  8. poj 1328 Radar Installation(贪心+快排)

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

  9. poj 1328 Radar Installation 排序贪心

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

随机推荐

  1. 轻量级RPC设计与实现第一版

    什么是RPC RPC (Remote Procedure Call Protocol), 远程过程调用,通俗的解释就是:客户端在不知道调用细节的情况下,调用存在于远程计算机上的某个对象,就像调用本地应 ...

  2. 4 Values whose Sum is 0 UVA 1152

    题目链接:https://vjudge.net/problem/UVA-1152 这题题意就是在四个集合内.每个集合分别里挑一个数a,b,c,d,求a+b+c+d=0有多少种选法. 暴力的话就是四重循 ...

  3. Web Workers - (Worker(专有) and SharedWorker(共享))

    Web Worker为Web内容在后台线程中运行脚本提供了一种简单的方法 线程可以执行任务而不干扰用户界面 可以使用XMLHttpRequest执行 I/O (尽管responseXML和channe ...

  4. Javaweb版四则运算

    显示出题界面shu01.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&quo ...

  5. 杭电oj_2047——阿牛的EOF牛肉串(java实现)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2047 思路:先是列出了四个,但是没发现规律,然后开始画递归树,在其中找到了规律,算出递归式为f(n) ...

  6. java自动化测试-json返回值校验

    参考: https://blog.csdn.net/xkhgnc_6666/article/details/50250283 实现举例:

  7. Appium学习2-Appium-desktop的使用

    安装: 下载路径:https://github.com/appium/appium-desktop/releases 选择最新的安装包即可. 使用 1.点击打开应用程序,进入到配置项. 2.配置以下信 ...

  8. python面试的100题(12)

    25.求出列表所有奇数并构造新列表 a=[1,2,3,4,5,6,7,8,9,10] res=[i for i in a if i%2==1] print(res) 结果为:[1, 3, 5, 7, ...

  9. crontab定时的使用

    //查看所有定时 crontab -l修改$ crontab -e //增加定时 //关闭定时 //删除定时$ crontab -r /sbin/service crond start //启动服务 ...

  10. 【SQL】基础概念

    1.. In order to find the rows where the value for a column is or is not NULL, you would use IS NULL  ...