POJ 1328 Radar Installation#贪心(坐标几何题)
#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#贪心(坐标几何题)的更多相关文章
- POJ 1328 Radar Installation 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
- poj 1328 Radar Installation(贪心+快排)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation 贪心算法
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- POJ 1328 Radar Installation 贪心 难度:1
http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...
- poj 1328 Radar Installation(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- POJ 1328 Radar Installation 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
随机推荐
- 使用Stardict命令行版本sdcv
sdcv命令的常用选项如下: -l:列出安装的词典 -u:指定查词所用的词典 在我的电脑上列出的词典有: Dictionary's name Word count Merrian Webster 10 ...
- Git提交到多个远程仓库
在已经习惯使用git同步写代码,github无疑是最的托管平台,但是国内由于"你懂的"原因,速度很慢,有时无法访问,于是想把自己的代码同步到多个不同的远程仓库备份. 我的主要仓库: ...
- elasticsearch+spark+hbase 整合
1.用到的maven依赖 <dependency> <groupId>org.apache.spark</groupId> <artifactId>sp ...
- PAT乙级1006. 换个格式输出整数 (15)
让我们用字母B来表示“百”.字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个“百”. ...
- qmake 小结(Qt 5.4)
FROMS 变量的定义必须在include之前. MOC_DIR UI_DIR RCC_DIR 的定义必须使用绝对路径.
- angular js一探
下一代angular js. 概念:mvc:作为dataModel的$scope. 还必须导入angular的库. ng-app:告诉angular引擎从这里开始是他因该管理的内容.(引入之后,可以在 ...
- Mysql的热备份[转载]
学一点 mysql 双机异地热备份----快速理解mysql主从,主主备份原理及实践 双机热备的概念简单说一下,就是要保持两个数据库的状态自动同步.对任何一个数据库的操作都自动应用到另外一个数据库,始 ...
- Java:注解(Annotation)自定义注解入门
转载地址:http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html 要深入学习注解,我们就必须能定义自己的注解,并使用注解,在定义自己的 ...
- java 用hmac-sha1进行签名
public static String getSignature(String s) throws NoSuchAlgorithmException, UnsupportedEncodingExce ...
- win7安装omnetpp-4.6
最近做毕设要用omnet仿真系统,就试着在win7上装了一下,分享一下经验咯.因为lz经常刷机,所以安装过程都是从头再来的,费话不多说.下面是安装过程: (1) 安装jdk,我就百度一下,然后找 ...