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 ...
随机推荐
- [NOI2013模拟] BZOJ4705 棋盘游戏 解题报告(组合计数)
莫名打不开这道题的链接,请读者自行搜索 Description 有一个N*M的棋盘,初始每个格子都是白色的.行操作是指选定某一行,将这行所有格子的颜色取反(黑白互换).列操作是指选定某一列,将这列所有 ...
- BMP图片格式模型
BMP BMP(全称Bitmap)是Window操作系统中的标准图像文件格式 可以分成两类:设备相关位图(DDB)和设备无关位图(DIB),使用非常广. 它采用位映射存储格式,除了图像深度可选以外,不 ...
- [学习笔记]AJAX学习
AJAX学习 ——在w3cschool学习AJAX的学习笔记 参考网站:w3cschool XMLHttpRequest 是 AJAX 的基础. XMLHttpRequest 对象 所有现代浏览器均支 ...
- JavaScript获取本机IP地址
<script type="text/javascript"> /** * Get the user IP throught the webkitRTCPeerConn ...
- 1、Go base64编码
package main import ( "encoding/base64" "fmt") func main() { //标准base64编码 data:= ...
- php八大设计模式之简介篇
设计模式的在面向对象中的重要性? 更深入的理解面向对象的思想,有利于开发出扩展性强的程序.在 PHP 面向对象中有一个 "开闭原则" :"软件实体应当对扩展开 ...
- centOS7下 安装nodejs+nginx+mongodb+pm2部署vue项目
一.购买服务器并远程连接 1.购买服务器和域名 可以选择阿里云或者是其他的厂商的服务器.然后会获得服务器ip地址,用户名和密码. 购买域名,将域名绑定到ip地址上. 2.下载xshell,winscp ...
- 学习优化《机器学习与优化》中文PDF+英文PDF
正在学习机器学习中的优化处理,感觉<机器学习与优化>写得还是比较通俗易懂的,第七章特征选择我需要,特征提取:相关系数,相关比,熵和互信息..更高级的应该是文本挖掘的特征提取,比如LDA提取 ...
- nginx配置aliyun https
server { listen 443; server_name www.goforit.com goforit.com; ssl on; ssl_certificate cert/goforit.p ...
- [HAOI2006]旅行(并查集)
寒假填坑五十道省选题——第五道 [HAOI2006]旅行 题目描述 Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N个景点(编号为1,2,3,…,N),这些景点被M条道路 ...