poj1328Radar Installation 贪心
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 64472 | Accepted: 14497 |
Description
distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.
We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write
a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

Figure A Sample Input of Radar Installations
Input
followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.
The input is terminated by a line containing pair of zeros
Output
Sample Input
3 2
1 2
-3 1
2 1 1 2
0 2 0 0
Sample Output
Case 1: 2
Case 2: 1
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> using namespace std; struct node
{
double L,R;
} p[1005];
int cmp(node p1,node p2)
{
return p1.L<p2.L;
}
int main()
{
int n,d,num=0;
while(cin>>n>>d)
{
num++;
if(n==0&&d==0)
break;
int flag=1;
for(int i=0; i<n; i++)
{
int u,v;
cin>>u>>v;
if(flag==0)
continue;
if(d<v) //注意半径能够取负的,所以不能用d*d<v*v比較
{
flag=0;
}
else
{
p[i].L=(double)u-sqrt((double)(d*d-v*v));
p[i].R=(double)u+sqrt((double)(d*d-v*v));
}
}
if(flag==0)
{
printf("Case %d: -1\n",num);
continue;
} sort(p,p+n,cmp);
double x=p[0].R;
int sum=1;
for(int i=1; i<n; i++)
{
if(p[i].R<x)
{
x=p[i].R;
}
else if(x<p[i].L)
{
sum++;
x=p[i].R;
}
}
printf("Case %d: %d\n",num,sum);
}
} /*把每一个岛屿来当做雷达的圆心。半径为d,做圆。与x轴会产生两个焦点L和R,这就是一个区间;
首先就是要把全部的区间找出来。然后x轴从左往右按L排序,再然后就是所谓的贪心
把那些互相重叠的区间去掉即可了区间也就是雷达;*/ /*
3 -3
1 2
-3 2
2 1
Case ... -1;
*/
//按R进行从左到右排序
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm> using namespace std; struct node
{
double L,R;
} p[1001];
int cmp(node p1,node p2)
{
return p1.R<p2.R;
}
int main()
{
int n,d,num=0;
while(cin>>n>>d)
{
num++;
if(n==0&&d==0)
break;
int flag=0;
for(int i=0; i<n; i++)
{
int u,v;
cin>>u>>v;
if(d<v)
{
flag=1; }
else if(flag==0)
{
p[i].L=u-sqrt(d*d-v*v);
p[i].R=sqrt(d*d-v*v)+u;
}
}
if(flag)
{
printf("Case %d: -1\n",num);
continue;
} sort(p,p+n,cmp);
double xR=p[0].R;
double xL=p[0].L;
int sum=1;
for(int i=1; i<n; i++)
{
if(p[i].L<=xR)
{
}
else if(p[i].L>xR)
{
xR=p[i].R;
sum++;
}
}
printf("Case %d: %d\n",num,sum);
}
}
poj1328Radar Installation 贪心的更多相关文章
- POJ1328Radar Installation(贪心)
对于每一个点,可以找到他在x轴上的可行区域,这样的话就变为了对区间的贪心. #include<iostream> #include<stdio.h> #include<s ...
- 【贪心】POJ1328-Radar Installation
[思路] 以每一座岛屿为圆心,雷达范围为半径作圆,记录下与x轴的左右交点.如果与x轴没交点,则直接退出输出“-1”.以左交点为关键字进行排序,从左到右进行贪心.容易知道,离每一个雷达最远的那一座岛与雷 ...
- POJ1328Radar Installation(区间点覆盖问题)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 68597 Accepted: 15 ...
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- Radar Installation(贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ...
- Radar Installation 贪心
Language: Default Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42 ...
- POJ1328 Radar Installation(贪心)
题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...
- Radar Installation(贪心,可以转化为今年暑假不ac类型)
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 ...
随机推荐
- 关于网易云音乐爬虫的api接口?
抓包能力有限,分析了一下网易云音乐的一些api接口,但是关于它很多post请求都是加了密,没有弄太明白.之前在知乎看到过一个豆瓣工程师写的教程,但是被投诉删掉了,请问有网友fork了的吗?因为我觉得他 ...
- PostgreSQL环境中查看SQL执行计划示例
explain analyze ,format,buffers, format :TEXT, XML, JSON, or YAML. EXPLAIN (ANALYZE,buffers,format ...
- <Sicily>Brackets Matching
一.题目描述 Let us define a regular brackets sequence in the following way: Empty sequence is a regular s ...
- iOS——集成支付宝 系统繁忙,请稍后再试ALI10
问题描述:调用支付宝时,显示系统繁忙,请稍后再试(ALI10).代码没有报错,其他也是按照文档来的,为何老是提示显示系统繁忙? 解决方案:还需要在targets的中info里面,添加 url typ ...
- 常用模块(hashlib、suprocess、configparser)
hashlib模块 hash是一种接受不了内容的算法,(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法),该算 ...
- 今日SGU 5.26
#include<bits/stdc++.h> #define de(x) cout<<#x<<"="<<x<<endl ...
- 一个Web报表项目的性能分析和优化实践(三) :提高Web应用服务器Tomcat的内存配置,并确认配置正确
摘要 上一篇,一个Web报表项目的性能分析和优化实践(一):小试牛刀,统一显示SQL语句执行时间 ,讲述了项目优化的整体背景,重点讲述了统一显示了Web项目SQL语句的执行时间. 本篇,将重点介绍提高 ...
- Vue2.0组件实现动态搜索引擎(一)
原文链接:https://blog.csdn.net/qwezxc24680/article/details/74550556 从github上看到一个不错的开源项目:https://github.c ...
- Unity 框架(一)
当项目需求中,后期可能接入多种输入设备的时候,可以借鉴一下以下代码 using System.Collections; using System.Collections.Generic; using ...
- 洛谷 P3199 [HNOI2009]最小圈
P3199 [HNOI2009]最小圈 题目背景 如果你能提供题面或者题意简述,请直接在讨论区发帖,感谢你的贡献. 题目描述 对于一张有向图,要你求图中最小圈的平均值最小是多少,即若一个圈经过k个节点 ...