poj 1328 Radar Installation 【贪心】【区间选点问题】
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 54798 | Accepted: 12352 |
Description
sea can be covered by a radius installation, if the distance between them is at most d.
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
two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.
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的圆,与x轴的相交,假设不相交那么肯定完不成任务,反之就转化成了区间选点问题。
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define M 1005 struct node {
double st, en;
}s[M]; int cmp(node a, node b){
if(a.en == b.en) return a.st > b.st;
return a.en<b.en;
} int main(){
int n, v = 1; double d;
while(scanf("%d%lf", &n, &d), n||d){
int i, j;
double a, b;
int flag = 0;
for(i = 0; i < n; i ++){
scanf("%lf%lf", &a, &b);
if(b>d) flag = 1;
if(flag == 0){
s[i].en = a+sqrt(d*d-b*b);
s[i].st = a-sqrt(d*d-b*b);
//printf("%lf %lf %d..\n", s[i].st, s[i].en, i);
}
// scanf("%lf%lf", &s[i].st, &s[i].en);
}
printf("Case %d: ", v++);
if(flag){
printf("-1\n"); continue;
}
sort(s, s+n, cmp);
int ans = 1;
double maxr = s[0].en;
i = 1, j = 0;
while(i < n){
if(s[i].st <= s[j].en){
//if(maxr < s[i].en) maxr = s[i].en;
++i;
}
else {
//if(j == i-1)
j = i;
++ans;
// maxr = s[i].en;
}
}
printf("%d\n", ans);
}
return 0;
}
poj 1328 Radar Installation 【贪心】【区间选点问题】的更多相关文章
- 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 贪心 A
POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...
- 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(贪心)
题目:http://poj.org/problem?id=1328 题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...
- 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 贪心题解
本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...
- POJ 1328 Radar Installation#贪心(坐标几何题)
(- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...
- 贪心 POJ 1328 Radar Installation
题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...
- POJ 1328 Radar Installation 【贪心 区间选点】
解题思路:给出n个岛屿,n个岛屿的坐标分别为(a1,b1),(a2,b2)-----(an,bn),雷达的覆盖半径为r 求所有的岛屿都被覆盖所需要的最少的雷达数目. 首先将岛屿坐标进行处理,因为雷达的 ...
随机推荐
- HDU 5889 Barricade(最短路+最小割水题)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- Cmake——CMake+SVN或Hg生成版本号
CMake+SVN或Hg生成版本号 原来的CMake需要用shell脚本生成SVN版本号,再作为cmake参数传入.CMake调用脚本示例: #!/bin/sh # cmake.sh ServerCo ...
- vue.js单文件组件中非父子组件的传值
最近在研究vue.js,总体来说还算可以,但是在web开发群里有一些人问在单文件组件开发模式中非父子组件如何传值的问题,今天在这里讲讲,希望对大家有所帮助! 在官网api中的这段讲解很少,也很模糊:官 ...
- 海拔(bzoj 2007)
Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作一个 正方形,每一个区域也可看作一个正方形.从而,YT城市中包括(n+1) ...
- BZOJ 3513: [MUTC2013]idiots
3513: [MUTC2013]idiots Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 476 Solved: 162[Submit][Stat ...
- 洛谷 P1783 海滩防御
题目描述 WLP同学最近迷上了一款网络联机对战游戏(终于知道为毛JOHNKRAM每天刷洛谷效率那么低了),但是他却为了这个游戏很苦恼,因为他在海边的造船厂和仓库总是被敌方派人偷袭.于是,WLP动用了他 ...
- BZOJ 3384 上帝与集合的正确用法
上帝与集合的正确用法 [问题描述] [输入格式] 第一行一个T,接下来T行,每行一个正整数p,代表你需要取模的值. [输出格式] T行,每行一个正整数,为答案对p取模后的值. [样例输入] 3236 ...
- yoga安装kali备忘(连接wifi)
kali 2.0 iso win8 下安装 用 WinSetupFromUSB-1-6-beta2 写入u盘,正常安装系统 启动连接wifi 搜索信号,获取ssid iw wlan0 scan 查看是 ...
- C#生成高清缩略图的方法
/// <summary> /// 为图片生成缩略图 /// </summary> /// <param name="phyPath">原图片的 ...
- JavaScript闭包 循环输出i
html <body> <p>产品一</p> <p>产品二</p> <p>产品三</p> <p>产品四& ...