Day3-C-Radar Installation POJ1328
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 简述:每个island与X轴都有最多2个交点,求最少点满足与所有区间相交
思路:区间选点问题,将每个区间右边递增排序后寻找即可,代码如下:
#define sqr(x) ((x)*(x))
const int maxm = ;
struct Node {
    double l, r;
    bool operator< (const Node &a) const {
        return r < a.r;
    }
} Nodes[maxm];
int d, n, sum, kase = ;
int main() {
    while(scanf("%d%d", &n, &d) && n) {
        printf("Case %d: ", ++kase);
        bool flag = true;
        sum = ;
        for (int i = ; i < n; ++i) {
            double tx, ty, tmp;
            scanf("%lf%lf", &tx, &ty);      //x = tx -+ sqrt(d^2 - y0 ^2 )
            if(d < ty) {
                flag = false;
                sum = -;
            }
            tmp = sqrt(sqr(d) - sqr(ty));
            Nodes[i].l = tx - tmp, Nodes[i].r = tx + tmp;
        }
        if(flag) {
            sort(Nodes, Nodes + n);
            double maxr = Nodes[].r;
            for (int i = ; i < n; ++i) {
                if(maxr < Nodes[i].l) {
                    maxr = Nodes[i].r;
                    ++sum;
                }
            }
        }
        printf("%d\n", sum);
    }
    return ;
}
注意在判断ty>d的时候不能提前退出,要读取完
补:
在区间选点问题上,要右端点进行排序,因为要找一个现有区间的公共点,若是左端点,会出现漏解的情况,例如:

Day3-C-Radar Installation POJ1328的更多相关文章
- [POJ1328]Radar Installation
		[POJ1328]Radar Installation 试题描述 Assume the coasting is an infinite straight line. Land is in one si ... 
- POJ1328——Radar Installation
		Radar Installation Description Assume the coasting is an infinite straight line. Land is in one side ... 
- POJ--1328 Radar Installation(贪心 排序)
		题目:Radar Installation 对于x轴上方的每个建筑 可以计算出x轴上一段区间可以包含这个点 所以就转化成 有多少个区间可以涵盖这所有的点 排序之后贪心一下就ok 用cin 好像一直t看 ... 
- POJ1328 Radar Installation 【贪心·区间选点】
		Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ... 
- 【贪心】「poj1328」Radar Installation
		建模:二维转一维:贪心 Description Assume the coasting is an infinite straight line. Land is in one side of coa ... 
- POJ1328 Radar Installation 解题报告
		Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ... 
- POJ 1328 Radar Installation 贪心 A
		POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ... 
- Radar Installation
		Radar Installation 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86640#problem/C 题目: De ... 
- Radar Installation(贪心)
		Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 56826 Accepted: 12 ... 
- 贪心 POJ 1328 Radar Installation
		题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ... 
随机推荐
- mark mark mark
			编译并使用静态lib---->>>>转自:Walkthrough: Creating and Using a Static Library (C++) 跟踪内存分配:http: ... 
- element table批量删除
			很小的一个问题,但是有细节需要注意 (1)问题:在起初我写的时候是根据元素的name是否相同判断是否是同一个节点,出现的问题就是,如果说两个元素的name相同,就会判断出错 (2)代码: <te ... 
- java调用exe
			前言:最近做了一个Java跨平台开启,关闭,重启nginx的功能,在Java操作exe上遇到了一些问题,下面是对这个问题一个总结 一.Java操作exe的三种方式 (1)Runtime.getRunt ... 
- 深度学习之父低调开源 CapsNet,欲取代 CNN
			“卷积神经网络(CNN)的时代已经过去了!” ——Geoffrey Hinton 酝酿许久,深度学习之父Geoffrey Hinton在10月份发表了备受瞩目的Capsule Networks(Cap ... 
- jquery  分页  Ajax异步
			//使用Ajax异步查询数据 <div class="table-responsive"> <table class="table table-bord ... 
- HDU 1035 Robot Motion(dfs + 模拟)
			嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1035 这道题比较简单,但自己一直被卡,原因就是在读入mp这张字符图的时候用了scanf被卡. ... 
- 常用的OpenCV 2.0函数速查
			OpenCV 2.0函数释义列表 1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像 ... 
- Flask - 性能分析(Profiling,profiler,profile)
			1. 疑问 @app.cli.command() @click.option('--length', default=25, help='Number of functions to include ... 
- 虚拟机与ubuntu系统的安装与基础操作
			1.虚拟机的下载: 常见的虚拟机软件有:VMware VirtuaIBOX Virtual PC 等. 这里主要介绍VMware ,VMware目前已经有很多个版本,可以根据个人情况进行选择.安 ... 
- vue学习笔记:vue的认识与特点与获取
			Vue了解 Vue:读作 view Vue是一个渐进式框架 与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计. Vue 的核心库只关注视图层,并且非常容易学习,非常容易与其它库或已有项目整 ... 
