(~ ̄▽ ̄)~*

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std; struct node
{
double l,r;
//找到以岛为圆心,以d为半径的圆与坐标x轴的左交点l、右交点r
//雷达只有设在l~r之间,岛才在雷达覆盖范围内
}a[1005]; int cmp(node a,node b)
{
return a.l<b.l;
} int main()
{
int n,d;
double right;
int Cas=0;
while(scanf("%d%d",&n,&d)&&n+d)
{
Cas++;
bool flag=1;
for(int i=0;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
a[i].l=x-sqrt(d*d*1.0-y*y*1.0);
a[i].r=x+sqrt(d*d*1.0-y*y*1.0);
int dis;
if(y<0) dis=-y;
else dis=y;
if(dis>d) flag=0;
}
if(!flag) printf("Case %d: -1\n",Cas);
else
{
int ans=1;
sort(a,a+n,cmp);
right=a[0].r;
for(int i=1;i<n;i++)
{
if(a[i].l>right)
{
ans++;
right=a[i].r;
}
if(a[i].r<right)
right=a[i].r;
}
printf("Case %d: %d\n",Cas,ans);
}
}
return 0;
}

POJ 1328 Radar Installation#贪心(坐标几何题)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

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

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

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

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

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

  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 贪心 难度:1

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

  6. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  7. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  8. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  9. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. centos 安装apache activemq

    安装说明 安装环境:CentOS-6.3 安装方式:源码安装  软件:apache-tomcat-7.0.29.tar.gz下载地址http://activemq.apache.org/downloa ...

  2. [SQL基础教程] 5-1视图

    [SQL基础教程] 5-1视图 视图和表 从SQL角度看视图就是一张表 视图与表的差别 表保存了实际的数据,视图保存的是SELECT语句: 视图的优点 节省存储空间: 将常用的Select 语句保存成 ...

  3. RelativeLayout各个属性

    android:layout_above="@id/xxx"  --将控件置于给定ID控件之上 android:layout_below="@id/xxx"  ...

  4. python json数组对象排序

    arr = [{"name": "name_1", "level": 1}, {"name": "name_2 ...

  5. C# 操作IIS -App & AppPools

    using System; using System.DirectoryServices; using System.Management; using Microsoft.Web.Administr ...

  6. TCP connect EADDRNOTAVAIL(99)错误原因分析

    转自:http://blog.chinaunix.net/uid-20662820-id-3371081.html 关于TCP connect 返回错误99,可以能大家都会遇到,这里就分析一下这个错误 ...

  7. Qt 打开指定的文件

    最近项目用到使用本地的office打开指定的文件,记录一下代码: QString fileName = QFileDialog::getOpenFileName(this, tr("Open ...

  8. java中的反射机制_____

    一,先看一下反射的概念: 主要是指程序可以访问,检测和修改它本身状态或行为的一种能力,并能根据自身行为的状态和结果,调整或修改应用所描述行为的状态和相关的语义. 反射是java中一种强大的工具,能够使 ...

  9. c#发送http请求注意

    这里要注意几个点:第一就是编码,如果编码不对,容易中文乱码第二就是ContentType 如果设置不对,有可能连方法都调试不进去(我api用的是MVC的普通controller)第三就是paramDa ...

  10. 一个IT人士的个人经历,给迷失方向的朋友(转)

    作者: 果子狸  来源: WP开发者社区  发布时间: 2013-11-08 10:43  阅读: 50078 次  推荐: 494   原文链接   [收藏] 这些日子我一直在写一个实时操作系统内核 ...