NYO Radar|| 外星人的供给站 (贪心)

Radar
时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the 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.


 


输入
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing 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
输出
For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
样例输入
3 2
1 2
-3 1
2 1


1 2
0 2


0 0
样例输出
Case 1: 2
Case 2: 1
来源
Beijing 2002
上传者
ctest
*/
/*
与外星人的供给站那道题一样

解题思路:
此题意思给定点集S={(xi,yi)i=1.2.3...n},
求用圆心在x轴上,半径为d的圆覆盖S所需的圆的最少个数。
1.先把给出的岛的坐标(xi.yi)和半径r转化为在x轴上的区间,
  即当d-yi>=0时,圆心位于x轴上的区间为Ii=[ xi-sqrt(d^2-yi^2) , xi + sqrt( d^2 - yi^2 )],
  则转化为区间选点问题。
2.S中点(xi,yi),对应一个在x轴上的区间Ii=(li,ri),按照区间右端点ri从小到大排序,
  在区间集合中选择一个索引最小的区间,把选择的区间和与其相交的所有区间作为一组从T中删除,
  直到T为空集、 
3.则剩下的分组的组数即为m的最小值、、、
*/

#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct node
{
double x;
double y;
}island[1010];


int cmp(node a,node b)
{
return a.y<b.y;
}


int main() 
{
    int N,d;
    int ca=1;
while(scanf("%d%d",&N,&d)&&(N||d))
{
int i,count=1;
double dis=0;
for(i=1;i<=N;i++)
{
int x,y;
scanf("%d%d",&x,&y);
dis=sqrt((d*d-y*y)*1.0);
island[i].x=x-dis;
island[i].y=x+dis;

}
sort(island+1,island+N+1,cmp);

dis=island[1].y;
for(i=2;i<=N;i++)
 if(island[i].x>dis)
 {
  count++;
  dis=island[i].y;
 }

 
printf("Case %d: %d\n",ca++,count);
}
return 0;

}


/*
外星人的供给站
时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述
外星人指的是地球以外的智慧生命。外星人长的是不是与地球上的人一样并不重要,但起码应该符合我们目前对生命基本形式的认识。比如,我们所知的任何生命都离不开液态水,并且都是基于化学元素碳(C)的有机分子组合成的复杂有机体。


42岁的天文学家Dr. Kong已经执著地观测ZDM-777星球十多年了,这个被称为“战神”的红色星球让他如此着迷。在过去的十多年中,他经常有一些令人激动的发现。ZDM-777星球表面有着明显的明暗变化,对这些明暗区域,Dr. Kong已经细致地研究了很多年,并且绘制出了较为详尽的地图。他坚信那些暗区是陆地,而亮区则是湖泊和海洋。他一直坚信有水的地方,一定有生命的痕迹。Dr. Kong有一种强烈的预感,觉得今天将会成为他一生中最值得纪念的日子。
    这天晚上的观测条件实在是空前的好,ZDM-777星球也十分明亮,在射电望远镜中呈现出一个清晰的暗红色圆斑。还是那些熟悉的明暗区域和极冠,不过,等等,Dr. Kong似乎又扑捉到曾看到过的东西,那是什么,若隐若现的。他尽可能地睁大了眼睛,仔细地辨认。哦,没错,在一条直线上,又出现了若干个极光点连接着星球亮区,几分钟后,极光点消失。


Dr. Kong大胆猜想,ZDM-777星球上的湖泊和海洋里一定有生物。那些极光点就是ZDM-777星球上的供给站,定期给这些生物提出维持生命的供给。


不妨设,那条直线为X轴,极光点就处在X轴上,N个亮区P1,P2,…Pn就分布在若干个极光点周围。








接着,Dr. Kong 又有惊人的发现,所有的亮区Pi都处在某个半径为R的极光点圆内。去掉一个极光点就会有某些亮区Pj不处在覆盖区域内。


Dr. Kong想知道,至少需要多少个极光点才能覆盖所有的湖泊和海洋。
输入
第一行: K 表示有多少组测试数据。 
接下来对每组测试数据:
第1行: N R
第2~N+1行: PXi PYi (i=1,…..,N)


【约束条件】
2≤K≤5 1≤R≤50 1≤N≤100 -100≤PXi PYi≤100 | PYi | ≤ R 
R, PXi PYi都是整数。数据之间有一个空格。
输出
对于每组测试数据,输出一行: 最少需要的极光点数。
样例输入
2
3 2
1 2
-3 1
2 1
1 5
5 5
样例输出
2
1
来源
第六届河南省程序设计大赛
上传者
ACM_赵铭浩


*/
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
struct node
{
double x;
double y;
}island[110];


int cmp(node a,node b)
{
return a.x<b.x;
}



int main() 
{
int K;
scanf("%d",&K);
while(K--)
{
int N,R;
scanf("%d%d",&N,&R);
int i,count=1;
double dis=0;
for(i=1;i<=N;i++)
{
int x,y;
scanf("%d%d",&x,&y);
dis=sqrt((R*R-y*y)*1.0);
island[i].x=x-dis;
island[i].y=x+dis;

}
sort(island+1,island+N+1,cmp);

dis=island[1].y;
for(i=2;i<=N;i++)
 if(island[i].x>dis)
 {
  count++;
  dis=island[i].y;
 }
 else 
 {
    if(island[i].y<dis)
      dis=island[i].y;
 }

printf("%d\n",count);
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值