C - C

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 

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<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .

We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -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<tex2html_verbatim_mark> - y<tex2html_verbatim_mark>coordinates.

<tex2html_verbatim_mark>

Input

The input consists of several test cases. The first line of each case contains two integers n<tex2html_verbatim_mark>(1n1000)<tex2html_verbatim_mark> and d<tex2html_verbatim_mark> , where n<tex2html_verbatim_mark> is the number of islands in the sea and d<tex2html_verbatim_mark> is the distance of coverage of the radar installation. This is followed by n<tex2html_verbatim_mark> 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<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
struct node
{
double l,r;
};
node a[];
int cmp(node a,node b)
{
return a.l<b.l;
}
int main()
{
int n,d;
int x,y,f,t;
int s=;
while(cin>>n>>d&&n&&d)
{
f=;
t=;
s++;
for(int i=; i<n; i++)
{
cin>>x>>y;
if(y>d)f=;
else
{
a[i].l=(double)x-sqrt((double)d*d-y*y);
a[i].r=(double)x+sqrt((double)d*d-y*y);
}
}
if(f==)
{
cout<<"Case "<<s<<": -1"<<endl;
continue;
}
sort(a,a+n,cmp);
double p=a[].r;
for(int i=; i<n; i++)
{ if(a[i].r<p)
p=a[i].r;
else if(p<a[i].l)
{
p=a[i].r;
t++;
}
}
cout<<"Case "<<s<<": "<<t<<endl; }
return ;
}

C题的更多相关文章

  1. java基础集合经典训练题

    第一题:要求产生10个随机的字符串,每一个字符串互相不重复,每一个字符串中组成的字符(a-zA-Z0-9)也不相同,每个字符串长度为10; 分析:*1.看到这个题目,或许你脑海中会想到很多方法,比如判 ...

  2. 【Java每日一题】20170106

    20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  3. 【Java每日一题】20170105

    20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  4. 【Java每日一题】20170104

    20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  5. 【Java每日一题】20170103

    20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  6. SQL面试笔试经典题(Part 1)

    本文是在Cat Qi的原贴的基础之上,经本人逐题分别在MySql数据库中实现的笔记,持续更新... 参考原贴:http://www.cnblogs.com/qixuejia/p/3637735.htm ...

  7. 刷LeetCode的正确姿势——第1、125题

    最近刷LeetCode比较频繁,就购买了官方的参考电子书 (CleanCodeHandbook),里面有题目的解析和范例源代码,可以省去非常多寻找免费经验分享内容和整理这些资料的时间.惊喜的是,里面的 ...

  8. AWS的SysOps认证考试样题解析

    刚考过了AWS的developer认证,顺手做了一下SysOps的样题.以下是题目和答案. When working with Amazon RDS, by default AWS is respon ...

  9. AWS开发人员认证考试样题解析

    最近在准备AWS的开发人员考试认证.所以特意做了一下考试样题.每道题尽量给出了文档出处以及解析. Which of the following statements about SQS is true ...

  10. 最近做了了解java基础的一些题,整理自己用到的一些函数和了解的一些名词

    [程序1]题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少? 程序分析: 兔子的规律为数列1,1,2, ...

随机推荐

  1. VMware宿主机和虚拟机的网络连接问题

    今天在win8上装了个vmware虚拟机,却发现一个vmware workstation宿主机ping不通centos虚拟机,宿主机和centos虚拟机都可以正常上网. 问题描述:今天在vmware ...

  2. OpenStack简单测试性能监控数据记录

  3. Azkaban2官方配置文档

    最近工作实在是太忙了,我把之前翻译的官方的文档先放上来吧,希望对大家有所帮助~ 介绍 Azkaban2新功能: 1.Web UI 2.简单工作流上传 3.更容易设置job的依赖关系 4.调度工作流 5 ...

  4. Paxos算法 Paxos Made Simple

    Paxos算法 Paxos Made Simple Leslie Lamport 2001.11.1 简介 Paxos算法,纯文本方式描述,非常简单. 1 介绍 为 实现具有容错能力的分布式系统而提出 ...

  5. 【算法与数据结构】在n个数中取第k大的数(基础篇)

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 题目介绍            在n个数中取第k大的数(基础篇),之所以叫基础篇是因为还有很多更高级的算法,这些 ...

  6. Dota兄订餐——静态代理(java)

    理解并使用设计模式,能够培养我们良好的面向对象编程习惯,同时在实际应用中,可以如鱼得水,享受游刃有余的乐趣. 代理模式是比较有用途的一种模式,而且变种较多,应用场合覆盖从小结构到整个系统的大结构,Pr ...

  7. Leetcode - Reverse Words

    比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,仅仅要注意各种极端情况就可以,不明确通过率为什么仅仅有13%. #include<iostream> #include<stri ...

  8. Cocostudio学习笔记(1) 扯扯蛋 + 环境搭建

    转眼七月份就到了,2014已经过了一半,而我也最终算是有"一年工作经验"了,开心ing. 回想这一年Cocos2dx的游戏开发经历,去年下半年重心主要在游戏的逻辑上,而今年上半年重 ...

  9. Java Applet读写client串口——终极篇

    測试环境: SDK:Oracle JRockit for Java version 6, Java Communication for Windows 2.0 OS:WINDOWS7 外设:串口条形码 ...

  10. Bigcommerce:intershop编程经验总结

    1.修改或者添加网页Title,Keywords,Decoration的代码: $full_url = $_SERVER['REQUEST_URI'];  //获取请求的url $letter = s ...