ZOJ-1360 || POJ-1328——Radar Installation
ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360
POJ地址:http://poj.org/problem?id=1328
解题思路:贪心
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <math.h>
5
6 struct P{
7 double x, y, left, right;
8 }p[];
9
int cmp(const void *a, const void *b){
struct P *c = (struct P *)a;
struct P *d = (struct P *)b;
return c->left > d->left ? : -;
}
int main(){
int n, i, j, r, ans, lose, Case = ;
double d, x, dis, high;
while(scanf("%d %d", &n, &r) != EOF){
if(n == && r == ){
break;
}
lose = ;
d = (double)r;
for(i = ; i < n; i++){
scanf("%lf %lf", &p[i].x, &p[i].y);
if(p[i].y > d){ //如果某个点的y左边大于雷达半径,那么一定无法覆盖
lose = ;
}
dis = sqrt(d * d - p[i].y * p[i].y);
p[i].left = p[i].x - dis;
p[i].right = p[i].x + dis;
}
if(lose == ){
printf("Case %d: -1\n", Case++);
continue;
}
qsort(p, n, sizeof(p[]), cmp);
ans = ;
high = p[].right; //令第一个点的右端点为最远点
for(i = ; i < n; i++){
if(p[i].left <= high){
high = p[i].right < high ? p[i].right : high;//如果该点的左端点在最远点内,更新最远点
}
else{ //如果左端点不在最远点内,雷达数+1,更新最远点
ans++;
high = p[i].right;
}
}
printf("Case %d: %d\n", Case++, ans);
}
return ;
53 }
ZOJ-1360 || POJ-1328——Radar Installation的更多相关文章
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
点击打开链接 Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43490 Accep ...
- poj 1328 Radar Installation【贪心区间选点】
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- poj 1328 Radar Installation(贪心)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation【贪心】
POJ 1328 题意: 将一条海岸线看成X轴,X轴上面是大海,海上有若干岛屿,给出雷达的覆盖半径和岛屿的位置,要求在海岸线上建雷达,在雷达能够覆盖全部岛屿情况下,求雷达的最少使用量. 分析: 贪心法 ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- poj 1328 Radar Installation 排序贪心
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56702 Accepted: 12 ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
随机推荐
- JQuery onload、ready 加载顺序
// ready 这个方法只是在页面所有的DOM加载完毕后就会触发 // 方式1 $(function(){ // do something }); // 方式2 $(document).ready( ...
- Java常见设计模式学习(非原创)
文章大纲 一.策略模式二.观察者模式三.工厂模式四.单例模式五.其他模式六.设计模式总结七.参考文章 一.策略模式 现在假设我们有个"鸭子项目",首先我们用OOP(面向对象)的 ...
- Android NFC 整理
Android NFC基础(多篇) http://blog.csdn.net/think_soft/article/details/8169483
- (动态规划)UVA-11400:Lighting System Design
You are given the task to design a lighting system for a huge conference hall. After doing a lot of ...
- Elasticsearch之探索集群信息
REST API 启动并运行了节点和集群,下一步是了解如何与它进行通信.elasticsearch提供了一个非常全面和强大的REST API,可以使用它与集群进行交付. 使用API完成以下: • 检查 ...
- 085 Maximal Rectangle 最大矩形
给定一个填充了 0 和 1 的二进制矩阵,找到最大的只包含 1 的矩形并返回其面积.例如,给出以下矩阵:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0返回 6 详见:http ...
- 118 Pascal's Triangle 帕斯卡三角形 杨辉三角形
给定 numRows, 生成帕斯卡三角形的前 numRows 行.例如, 给定 numRows = 5,返回[ [1], [1,1], [1,2,1], [1,3,3,1], [1 ...
- python学习之列表元组,字典
list:元素性质可以不一致,元素还可以是list,可类似数组方法进行索引(也可以用负数索引,-1表示最后一个),可用.append('')进行动态增加,可用pop()删除最后一个或者pop(i)删除 ...
- watir-webdriver使用过程中异常
1.在jruby版本1.6.7中,报异常:not such file to load --watir-webdriver 解决方法 :在文件的首行添加:require 'rubygems' ...
- ubuntu 下 docker安装
1移除以前安装docker sudo apt-get remove docker docker-engine docker-ce docker.io 2 安装包以允许apt通过HTTPS使用存储库 s ...