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.
Input
The input consists of several test cases. The first line of each case contains two integers n<tex2html_verbatim_mark>(1n
1000)<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题的更多相关文章
- java基础集合经典训练题
第一题:要求产生10个随机的字符串,每一个字符串互相不重复,每一个字符串中组成的字符(a-zA-Z0-9)也不相同,每个字符串长度为10; 分析:*1.看到这个题目,或许你脑海中会想到很多方法,比如判 ...
- 【Java每日一题】20170106
20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170105
20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170104
20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170103
20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- SQL面试笔试经典题(Part 1)
本文是在Cat Qi的原贴的基础之上,经本人逐题分别在MySql数据库中实现的笔记,持续更新... 参考原贴:http://www.cnblogs.com/qixuejia/p/3637735.htm ...
- 刷LeetCode的正确姿势——第1、125题
最近刷LeetCode比较频繁,就购买了官方的参考电子书 (CleanCodeHandbook),里面有题目的解析和范例源代码,可以省去非常多寻找免费经验分享内容和整理这些资料的时间.惊喜的是,里面的 ...
- AWS的SysOps认证考试样题解析
刚考过了AWS的developer认证,顺手做了一下SysOps的样题.以下是题目和答案. When working with Amazon RDS, by default AWS is respon ...
- AWS开发人员认证考试样题解析
最近在准备AWS的开发人员考试认证.所以特意做了一下考试样题.每道题尽量给出了文档出处以及解析. Which of the following statements about SQS is true ...
- 最近做了了解java基础的一些题,整理自己用到的一些函数和了解的一些名词
[程序1]题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子对数为多少? 程序分析: 兔子的规律为数列1,1,2, ...
随机推荐
- Nodejs in Visual Studio Code 14.IISNode与IIS7.x
1.开始 部署IISNode环境请参考:Nodejs in Visual Studio Code 08.IIS 部署Nodejs程序请参考:Nodejs in Visual Studio Code 1 ...
- UVa11419 SAM I AM(构造最小点覆盖)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27475 [思路] 二分图的最小点覆盖以及构造最小覆盖. 二分图的最 ...
- MySQL 创建库
CREATE DATABASE IF NOT EXISTS database_name DEFAULT CHARSET utf8 COLLATE utf8_general_ci; 这种创建方式能保证数 ...
- 双有序队列算法——处理哈夫曼K叉树的高效算法
算法介绍: 哈夫曼树的思路及实现众所周知,大部分是用堆来维护和实现,这种思路比较清晰,在K比较小的时候处理较快(具体例子接下来再说),而且编程复杂度不是很高,利于应用.但是,其所用的数据结构是树,是在 ...
- angularJS constant和value
angularJS可以通过constant(name,value)和value(name,value)对于创建服务也是很重要的. 相同点是:都可以接受两个参数,name和value. 区别: 1.co ...
- Confluence5.1 最新版的安装&破解&汉化
转自 博客 http://seanzhou.iteye.com/blog/1287016 亲自基本上按照这个教程装了一遍,成功运行. 1.介绍 Atlassian Confluence(简称Confl ...
- C# WinForm登录窗口代码
Main窗体为应用程式主窗体,Login为登录窗体.均为SDI窗体. 两种实现方式如下: 1.应用程式入口放在Login窗体,在Login窗体实现登录机制,验证通过则创建Main窗体的实例,并 ...
- 强迫症和拖延症患者如何应对马桶4(遨游Maxthon)“上次未关闭页面”丢失的问题
强迫症和拖延症患者如何应对马桶4(遨游Maxthon)“上次未关闭页面”丢失的问题 用了马桶好多年,虽然一直bug不断,经常假死丢数据坑爹什么的,但是总得来说还是略有感情,不忍舍弃. 马桶一直有一个好 ...
- 【转】四种常见的POST提交数据方式
HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 POST 一般用来向服务端提交数据,本文 ...
- pythonQQ邮件
http://www.cnblogs.com/lonelycatcher/archive/2012/02/09/2343463.html http://blog.csdn.net/imzoer/art ...