Radar Installation(POJ 1328 区间贪心)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 68578 | Accepted: 15368 |
Description
We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-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-y coordinates.
Figure A Sample Input of Radar Installations
Input
The input is terminated by a line containing pair of zeros
Output
Sample Input
3 2
1 2
-3 1
2 1 1 2
0 2 0 0
Sample Output
Case 1: 2
Case 2: 1 需要判断d<0,a[i].y>d情况。
首先,按照x坐标排序,对于每个岛屿求出雷达所能放置的区间,然后对这些进行处理,x1,x2;
设当前雷达放置位置为nowx,对于下一个区间,如果写x1>nowx,显然多需要一个雷达,反之如果nowx>x1,nowx=min(nowx,x2);
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
struct node
{
int x,y;
}a[+];
bool cmp(node q,node p)
{
if(q.x==p.x)
return q.y>=p.y;
return q.x<p.x;
}
int main()
{
int n,d;
int i,j;
int k=;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&d))
{
int coun=;
if(n==&&d==)
break;
bool flag=;
for(i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if(a[i].y>d)
flag=;
}
if(flag||d<=)
{
printf("Case %d: -1\n",k++);
continue;
}
sort(a,a+n,cmp);
double nowx=sqrt(double(d*d-a[].y*a[].y))+a[].x;
double x1,x2,temp;
for(i=;i<n;i++)
{
temp=sqrt(double(d*d-a[i].y*a[i].y));
x1=a[i].x-temp;
x2=a[i].x+temp;
if(x1>nowx)
{
nowx=x2;
coun++;
}
else if(nowx>x2)
nowx=x2;
}
printf("Case %d: %d\n",k++,coun);
}
}
Radar Installation(POJ 1328 区间贪心)的更多相关文章
- Radar Installation POJ - 1328(贪心)
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- Radar Installation POJ - 1328 (贪心)
题目大意(vj上的翻译版本) 假定海岸线是无限长的直线.陆地位于海岸线的一侧,海洋位于另一侧.每个小岛是位于海洋中的一个点.对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的 ...
- Radar Installation POJ - 1328
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- Greedy:Radar Installation(POJ 1328)
装雷达 题目大意,就是令在海岸线的(直线)一边是海(y>0),另一边是陆地(y<=0),在海岸线上装雷达,雷达可以覆盖的范围为d,海上有岛,(x,y),问你应该怎么装雷达,才能做到技能雷达 ...
- UVALive 2519 Radar Installation 雷达扫描 区间选点问题
题意:在坐标轴中给出n个岛屿的坐标,以及雷达的扫描距离,要求在y=0线上放尽量少的雷达能够覆盖全部岛屿. 很明显的区间选点问题. 代码: /* * Author: illuz <iilluzen ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
- poj 1328 Radar Installation【贪心区间选点】
Radar Installation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- POJ 1328 Radar Installation(很新颖的贪心,区间贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 106491 Accepted: 2 ...
- POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)
Input The input consists of several test cases. The first line of each case contains two integers n ...
随机推荐
- 分数(有理数)的四则运算PAT1088
2015-02-05 PAT- B1088. Rational Arithmetic (20) http://www.patest.cn/contests/pat-a-practise/1088 #i ...
- async 异步流程控制规则
github 学习async网址 : https://github.com/caolan/async/ 1.Async 函数介绍 async 主要实现了三个部分的流程控制功能 1.集合:Collect ...
- 使用CURL发彩信,短信和进行多线程
短彩信发送 01 $xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="y ...
- man手册导出成txt,pdf,html的一些小技巧
经常man一些shell命令,有时候有想导出来编辑或注释一下,所以要导出.方法有很多种,根据自己的实际需要觉得比较实用的记录下分享一下. 1.导出成txt man –t bash |col –b &g ...
- LeetCode_Rotate Image
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- LeetCode_N-Queens
The n-queens puzzle is the problem of placing n queens on an n�n chessboard such that no two queens ...
- Square spiral
Square spiral Nikola picks up a strange circuit board. All of its elements are connected in a spiral ...
- 腾讯TT浏览器应用程序发生异常(0xc0000409) 位置为0x027a1f7f 的解决办法
2013年8月26日下午,腾讯TT浏览器 4.8版1000 出现“应用程序发生异常(0xc0000409) 位置为0x027a1f7f ”的错误,导致浏览器自动关闭. 无论重新卸载安装还是 清理系统 ...
- python爬爬(网友提供学习)
import urllib2,urllib,os,re def ZZ(url): pathw=os.getcwd() #图片和标题目录 imagetitleregion=r'<div class ...
- IOS UIImage 模糊
#import <UIKit/UIKit.h> #import <Accelerate/Accelerate.h> #import <QuartzCore/QuartzC ...