(~ ̄▽ ̄)~*

#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. SUSE Linux 下redis 的坑

    前面redis服务器安装-SuSE Linux Enterprise Server 11 SP3一章中安装好提示开放防火墙后的一些坑 前面漏了说明redis作为一个高速数据库,在互联网上,对应的安全机 ...

  2. [SOJ] Babelfish

    Description You have just moved from Waterloo to a big city. The people here speak an incomprehensib ...

  3. 网站URL重写(Java UrlRewrite 的使用)

    现在大部分的网站和商城都会使用到URL重写,接触到这个,也是因为正在做的电子商务商城.URL重写,是将原有的URL采用另一种规则来显示,使得用户方便访问同时也屏蔽一些信息. 在此说下它的好处,在开发过 ...

  4. Java 不使用科学计数法表示数据设置

    java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); nf.setGroupingUsed(false); nf.form ...

  5. 信息设计工具IDT创建从SAP Business Object到SAP HANA的连接

    1. 打开Information Design Tool, 并添加BO Server的连接 2. 在Connection上右击, 选择Insert Relational Connection 3. 输 ...

  6. java操作mongodb——更新数据

    Java中可以通过updateOne,updateMany,replaceOne方法进行集合的文档更新.但是 _id 是不能更新的 updateOne只会更新一条数据,即使通过Filters.lt(& ...

  7. java程序基础

  8. 关于泛型中<T extends comparable>的理解

    public static <T extends Comparable> T min(List<T> t); 对于上面定义的泛型方法min中,Comparable指的是一个接口 ...

  9. UML(Unified Modeling Language)同一建模语言

    wiki定义: UML is a general-purpose, developmental, modeling language in the field of software engineer ...

  10. [M]表格中的天正文字转换问题

    若表格中含有天正文字,则不能使用MagicTable直接转换,需要先EXPLODE命令分解(快捷键为x),天正单行文字和天正多行文字都可以使用该命令分解为普通AutoCAD单行文字,分解后即可正常转换 ...