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 ...
随机推荐
- win7、win8.1淡绿色护眼模式设置
Win7设置: 右击桌面 -> 个性化 -> 窗口颜色 -> 高级外观设置 选中 -> 项目:窗口 颜色:其他 修改:色调 饱和度 亮度 红 绿 蓝 添加到自定义 ...
- Ubuntu安装Python机器学习包
1.安装pip $ mkdir ~/.pip $ vi ~/.pip/pip.conf [global] trusted-host=mirrors.aliyun.com index-url=http: ...
- winServer2008添加IIS服务
右键我的电脑,选择管理,打开服务器管理器 点击左边菜单栏角色调出角色窗口 接着点击添加角色,弹出添加角色向导 点击下一步进入服务器角色选项 勾选Web服务器(IIS),点击下一步 出现 点击下一步,出 ...
- nginx在window上无法启动的问题
内容列表: 简要介绍 下载安装 配置测试 一.简要介绍 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP ...
- Web Scraper使用
{ "selectors": [{ "parentSelectors": ["_root"], "type": &quo ...
- ios下iphone的plus下
二维码能被长按识别,但因为某种原因识别区域发生了偏移 meta标签定义了默认缩放为一倍就能识别,不定义就不能识别. 网上是这么说的: meta标签定义了默认缩放为一倍就能识别,不定义就不能识别.于是我 ...
- tcp异常终止连接
服务端: #include <sys/socket.h> #include <unistd.h> #include <sys/types.h> #include & ...
- PXE+kickstart自动安装ubuntu14.04
本文参考了诸多文章,先感谢这些文章的作者. 使用pxe安装系统需要安装dhcp,tftp,http等服务(当然也可以使用其他文件共享方式比如nfs,ftp). 实验环境: 1. vmware 12 2 ...
- Python学习笔记——基础篇【第七周】———进程、线程、协程篇(socket基础)
http://www.cnblogs.com/wupeiqi/articles/5040823.htmlhttp://i.cnblogs.com/EditPosts.aspx?postid=55437 ...
- Android数据库--Sqlcipher的使用(一)
1.下载官方支持包:https://s3.amazonaws.com/sqlcipher/3.2.0/sqlcipher-for-android-community-v3.2.0.zip Github ...