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 ...
随机推荐
- c# IOCP.ClientEx2.ReadWrite 加断点遭遇System.AccessViolationException 问题
起因: 如果在Debug模式下,在IOCP.ClientEx2.ReadWrite.cs while (0 > (nPackSize = _ipcp.Pack(arg_n64PackId, ar ...
- 搭建Keepalived + Nginx + Tomcat的高可用负载均衡架构
1 概述 初期的互联网企业由于业务量较小,所以一般单机部署,实现单点访问即可满足业务的需求,这也是最简单的部署方式,但是随着业务的不断扩大,系统的访问量逐渐的上升,单机部署的模式已无法承载现有的业务量 ...
- 黑马MySQL数据库学习day02 表数据CRUD 约束CRUD
/* 基础查询练习: 1.字段列表查询 当查询全部字段时,一种简便方式,使用*代替全部字段(企业中不推荐使用) 2.去除重复行 DISTINCT,注意修饰的是行,也就是整个字段列表,而不是单个字段. ...
- PHP之session
p:first-child, #write > ul:first-child, #write > ol:first-child, #write > pre:first-child, ...
- 090 Subsets II 子集 II
给定一个可能包含重复整数的列表,返回所有可能的子集(幂集).注意事项:解决方案集不能包含重复的子集.例如,如果 nums = [1,2,2],答案为:[ [2], [1], [1,2,2], ...
- js获取窗口参数
window.onscroll=function getScrollTop(){ console.log(scrollTop) if(document.documentElement&& ...
- css3のtext-shadow
text-shadow,让我们大家一起来学习一下吧. 语法: text-shadow:none | <shadow> [ , <shadow> ]* <shadow> ...
- asp。Net 页面传值
00.引言 Web页面是无状态的, 服务器对每一次请求都认为来自不同用户,因此,变量的状态在连续对同一页面的多次请求之间或在页面跳转时不会被保留.在用ASP.NET 设计开发一个Web系统时, 遇到一 ...
- spring mvc 获取所有注册的url
背景:坑货同事写代码一点规范都没有,瞎写,根据url没法直接定位到方法,无奈产生了此接口,程序员何苦为难程序员呢 @Autowired private RequestMappingHandlerMap ...
- Ubuntu系统下安装字体和切换默认字体的方法
参考链接:http://my.oschina.net/itblog/blog/278566 打开Ubuntu的软件中心,搜索:tweak,安装[Unity Tweak Tool]这款软件,如图(由于我 ...