Radar Installation

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 54   Accepted Submission(s) : 28
Problem Description
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d 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
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is 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
For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
 
Sample Input
3 2 1 2 -3 1 2 1 1 2 0 2 0 0
 
Sample Output
Case 1: 2 Case 2: 1
题解:先转化为区间点,再排序,区间找点;
代码:
 #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct Node{
double s,e;
};
int n,d,k;
Node area[];
int cmp(Node a,Node b){
return a.e<b.e;
}
int change(int x,int y){
if(y>d)return ;
double a,b,m=sqrt(d*d-y*y);
a=x-m;b=x+m;
area[k].s=a;area[k].e=b;k++;
return ;
}
int main(){int t,x,y,flot,temp,num,l=;
while(scanf("%d%d",&n,&d),n||d){k=;flot=;temp=;num=;l++;
for(int i=;i<n;i++){
scanf("%d%d",&x,&y);
t=change(x,y);
if(!t)flot=;
}
sort(area,area+k,cmp);
for(int i=;i<k;i++){
if(area[i].s>area[temp].e)temp=i,num++;
}
printf("Case %d: %d\n",l,num);
}
return ;
}

Radar Installation(贪心,可以转化为今年暑假不ac类型)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. Radar Installation(贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 56826   Accepted: 12 ...

  3. Radar Installation 贪心

    Language: Default Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42 ...

  4. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  6. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  7. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  8. POJ1328 Radar Installation(贪心)

    题目链接. 题意: 给定一坐标系,要求将所有 x轴 上面的所有点,用圆心在 x轴, 半径为 d 的圆盖住.求最少使用圆的数量. 分析: 贪心. 首先把所有点 x 坐标排序, 对于每一个点,求出能够满足 ...

  9. poj1328 Radar Installation —— 贪心

    题目链接:http://poj.org/problem?id=1328 题解:区间选点类的题目,求用最少的点以使得每个范围都有点存在.以每个点为圆心,r0为半径,作圆.在x轴上的弦即为雷达可放置的范围 ...

随机推荐

  1. python3-day1(基础总结)

    总结比较抽象的难点: 1.二进制运算 60 & 13  =12 60 |  13  =61 60 ^ 13  =49 60<<2   =240 60>>2   =15 ...

  2. mmc加工配套问题

    题目如下,本题还有其它解.

  3. linux TIME_WAIT过多的解决方法

      查看TCP状态:netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'查看SOCKET状态:cat /proc/n ...

  4. fedora 20下安装vim的C++补全插件clang_complete

    1.安装clang yum install clang 2.安装clang_complete插件 git clone https://github.com/Rip-Rip/clang_complete ...

  5. Ubuntu的防火墙UFW

    这是个简单的防火墙,可以直接在命令行启停,也可安装提图形端gufw *安装 sudo apt-get install ufw gufw *常用命令 sudo ufw enable //启动 ufw d ...

  6. ThinkPHP视图查询详解

    ThinkPHP视图查询详解 参考http://www.jb51.net/article/51674.htm   这篇文章主要介绍了ThinkPHP视图查询,需要的朋友可以参考下     ThinkP ...

  7. oracle开启/关闭归档模式

    1.改变非归档模式到归档模式: 1)SQL> conn / as sysdba (以DBA身份连接数据库) 2)SQL> shutdown immediate;(立即关闭数据库) 3)SQ ...

  8. Android 使用图标字体库

    首先,在assets资源文件下放入图标字体库. 我这儿采用的是fontawesome-webfont.ttf 然后, 在安卓中加载这个资源文件 Typeface fontFace = Typeface ...

  9. Unity-视图操作

    按下 F 键使画面的视角移动到被选中对象的正面 视图场景摄像机(14年的时候,这个操作弄的头晕--) 旋转:Alt(Command)+左键拖拽 平移:Alt+Ctrl(Command)+左键拖拽 旋转 ...

  10. java基础知识1

    58.线程的基本概念.线程的基本状态以及状态之间的关系线程指在程序执行过程中,能够执行程序代码的一个执行单位,每个程序至少都有一个线程,也就是程序本身.Java中的线程有四种状态分别是:运行.就绪.挂 ...