Radar Installation

原文是English,直接上中文

Descriptions:

假定海岸线是无限长的直线。陆地位于海岸线的一侧,海洋位于另一侧。每个小岛是位于海洋中的一个点。对于任何一个雷达的安装 (均位于海岸线上),只能覆盖 d 距离,因此海洋中的小岛被雷达安装所覆盖的条件是两者间的距离不超过 d 。

我们使用卡笛尔坐标系,将海岸线定义为 x 轴。海洋的一侧位于 x 轴上方,陆地的一侧位于下方。给定海洋中每个小岛的位置,并给定雷达安装的覆盖距离,您的任务是写一个程序,找出雷达安装的最少数量,使得所有的小岛都被覆盖。注意:小岛的位置以它的 x-y 坐标表示。

图 A: 雷达安装的示例输入

Input

输入由多个测试用例组成。每个测试用例的第一行,包含了两个整数 n (1<=n<=1000) 和 d,其中 n 是海洋中小岛的数目,d 是雷达安装的覆盖距离。接下来是 n 行,每行包含了两个整数,表示每个小岛的坐标。每组测试用例之间,以一个空行间隔。

Output

对于每个测试用例,输出一行,包括测试用例的编号,以及雷达安装所需的最小数量。"-1" 个安装,表示该测试用例无解决方案。

Sample Input

3 2
1 2
-3 1
2 1 1 2
0 2 0 0

Sample Output

Case 1: 2
Case 2: 1

题目链接:

https://vjudge.net/problem/OpenJ_Bailian-1328

雷达必须在x轴的[s[i].left,s[i].right]之间,每个小岛都有对应在x轴的点是s[i].left和s[i].right,问题转换成用最少的点,使所有的线段都被覆盖到

AC代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define ME0(x) memset(x,0,sizeof(x))
using namespace std;
struct point
{
double left,right;//线段两端
bool operator<(const point &c)const//按做端点排序
{
return left<c.left;
}
};
point points[];
int n,d;
int sum=;
int f=;
//求每个Case
int solve()
{
int ans=;//雷达个数
double nowpos;
sort(points,points+n);
// for(int i=0; i<n; i++)
// cout<<points[i].left<<" "<<points[i].right<<endl;
nowpos=points[].right;
for(int i=; i<n; ++i)
{
// cout<<"*"<<endl;
if(points[i].left<=nowpos)
nowpos=min(nowpos,points[i].right);
else//若当前线段与目前线段没有交集,则加入新雷达
{
++ans;
nowpos=points[i].right;
}
}
return ans;
}
int main()
{
while(cin>>n>>d,n+d)
{
f=;
sum++;
int x,y;
for(int i=; i<n; ++i)
{
cin>>x>>y;
if(y>d)
f=;
else
{
double t=d*d-y*y;
points[i].left=x-sqrt(t);
points[i].right=x+sqrt(t);
}
}
if(f)
printf("Case %d: %d\n",sum,solve());
else
printf("Case %d: -1\n",sum);
}
}

【OpenJ_Bailian - 1328】Radar Installation (贪心)的更多相关文章

  1. POJ 1328 Radar Installation 贪心 A

    POJ 1328 Radar Installation https://vjudge.net/problem/POJ-1328 题目: Assume the coasting is an infini ...

  2. poj 1328 Radar Installation(贪心+快排)

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  3. POJ - 1328 Radar Installation(贪心区间选点+小学平面几何)

    Input The input consists of several test cases. The first line of each case contains two integers n ...

  4. POJ 1328 Radar Installation 贪心算法

    Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...

  5. POJ 1328 Radar Installation 贪心 难度:1

    http://poj.org/problem?id=1328 思路: 1.肯定y大于d的情况下答案为-1,其他时候必定有非负整数解 2.x,y同时考虑是较为麻烦的,想办法消掉y,用d^2-y^2获得圆 ...

  6. poj 1328 Radar Installation(贪心)

    题目:http://poj.org/problem?id=1328   题意:建立一个平面坐标,x轴上方是海洋,x轴下方是陆地.在海上有n个小岛,每个小岛看做一个点.然后在x轴上有雷达,雷达能覆盖的范 ...

  7. POJ 1328 Radar Installation 贪心题解

    本题是贪心法题解.只是须要自己观察出规律.这就不easy了,非常easy出错. 一般网上做法是找区间的方法. 这里给出一个独特的方法: 1 依照x轴大小排序 2 从最左边的点循环.首先找到最小x轴的圆 ...

  8. POJ 1328 Radar Installation#贪心(坐标几何题)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<algorithm> #include<cmath ...

  9. 贪心 POJ 1328 Radar Installation

    题目地址:http://poj.org/problem?id=1328 /* 贪心 (转载)题意:有一条海岸线,在海岸线上方是大海,海中有一些岛屿, 这些岛的位置已知,海岸线上有雷达,雷达的覆盖半径知 ...

  10. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

随机推荐

  1. 九度OJ 1130:日志排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1265 解决:303 题目描述: 有一个网络日志,记录了网络中计算任务的执行情况,每个计算任务对应一条如下形式的日志记录: "hs ...

  2. java web service

    1.编写服务代码 服务代码提供了两个函数,分别为sayHello和sayHelloToPerson,源代码如下: /* * File name: HelloService.java * * Versi ...

  3. Struts表单重复提交

  4. ICE学习笔记 -- RFC 5245

    RFC 5245 ICE   1, offer/answer model 2, ICE Step:    1) 产生候选地址(1.公网 2.NAT反射 3.Relay转发地址) Generate ca ...

  5. 负载均衡LVS

    可参考:http://ixdba.blog.51cto.com/2895551/555738 http://os.51cto.com/art/201202/319979.html 也可以参考官网:ht ...

  6. [haoi2011]a

    一次考试共有n个人参加,第i个人说:“有ai个人分数比我高,bi个人分数比我低.”问最少有几个人没有说真话(可能有相同的分数) 题解:首先,由每个人说的话的内容,我们可以理解为他处在ai+1,n-bi ...

  7. cookie VS sessionstorge VS localstorge

    虽然cookie , localstorge , sessionstorge三者都有存储的功能,但是还是有区别, git上地址:https://github.com/lily1010/cookie-s ...

  8. python多进程执行任务

    https://blog.csdn.net/qq_39694935/article/details/84552076 [Python]multiprocessing Pool 进程间通信共享 直接上代 ...

  9. codeforces 463C. Gargari and Bishops 解题报告

    题目链接:http://codeforces.com/contest/463/problem/C 题目意思:要在一个 n * n 大小的棋盘上放置两个bishop,bishop可以攻击的所有位置是包括 ...

  10. python berkeley DB操作——打开btree索引文件中的database

    打开BDB中某个索引中的数据库代码: from bsddb3 import db import bsddb3 as bsddb print db.DB_VERSION_STRING mydb = db ...