poj 1328 Radar Installation【贪心区间选点】
Radar Installation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 22 Accepted Submission(s) : 9
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
The input is terminated by a line containing pair of zeros
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<math.h>
- using namespace std;
- #define MAX 11000
- struct node
- {
- double beg;
- double end;
- }s[MAX];
- bool cmp(node a,node b)
- {
- return a.beg<b.end;
- }
- int main()
- {
- int i,j;
- int island,r;
- double a,b;
- int k=0;
- while(scanf("%d%d",&island,&r)&&island!=0&&r!=0)
- {
- int ok=0;
- for(i=0;i<island;i++)
- {
- scanf("%lf%lf",&a,&b);
- if(fabs(b)>r)
- {
- ok=1;
- break;
- }
- s[i].beg=a-sqrt(r*r-b*b);//区间左端
- s[i].end=a+sqrt(r*r-b*b);//区间右端
- }
- if(ok)
- {
- printf("-1\n");
- continue;
- }
- sort(s,s+island,cmp);
- int sum=0;
- double ans=-11000.0;
- for(i=0;i<island;i++)
- {
- if(ans<s[i].beg)
- {
- ans=s[i].end;
- sum++;
- }
- }
- printf("Case %d: ",++k);
- printf("%d\n",sum);
- }
- return 0;
- }
poj 1328 Radar Installation【贪心区间选点】的更多相关文章
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- 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(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- 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(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
随机推荐
- 用QT 还是MFC ? (转)
我曾经使用过QT和MFC来开发过软件,我想和大家分享我使用他们时所体会的不同之处. 我并非一个职业作家,这篇文章可能看起来不如专业的杂志和网站上的那么条理清晰.但是,我在这里是用我自己的语言来表达我自 ...
- 【elasticsearch】(1)centos7 使用yum安装elasticsearch 2.X
前言 elasticsearch(下面称为ES)是一个基于Lucene的搜索服务器(By 百度百科:查看).所以他需要java的环境即jdk,这里提供懒人一键安装方式 # yum install ja ...
- js 组件的写法
var Test1 = function(){ var name = ""; this.setName = function(username){ name = username; ...
- JS中关于clientWidth offsetWidth srollWidth等的含义
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
- x的平方根
class Solution { public: /** * @param x: An integer * @return: The sqrt of x */ int getResult(long s ...
- 实现Action(含Action访问ServletAPI)
Action里是否包含实例变量不重要,重要的是包含setter和getter方法. Action可用于封装请求参数和处理结果.jsp中使用struts2输出:<s:property value= ...
- php 扩展编译linux
进入扩展库目录:$cd phpredis-master 需要root权限执行 执行:$ phpize 执行:$ ./configure 执行:$ make 执行:$ make install 编译 ...
- CURL传输与获取功能
什么是CURL? 利用URL语法爱命令行方式下工作的文件传输工具.它支持很多协议.它支持认证功能.php中常用都实现更复杂的传输功能. 实现的功能: 1.实现远程获取和采集内容 2.实现PHP 网页版 ...
- 简单python2.7.3安装setuptools模块
下载setuptools https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg 安装 .6c11- ...
- 外包如何安排人手-b
前几天跟一位做人事的朋友聊天,说起软件行业人员问题.朋友的公司是做软件外包的.一个APP项目基本配置6-7个人,每个Android.ios.后台都各配2人以上,但是项目各种超期.各种无法交付.各种客户 ...