/*
* POJ_1328.cpp
*
* Created on: 2013年11月18日
* Author: Administrator
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1010;
struct tt{
double l,r;
}p[maxn];
int n,d;
bool flag;
void init(){
flag = true;
int i;
double x,y;
for(i = 1 ; i <= n ; ++i){
scanf("%lf%lf",&x,&y);
if(d < y){
flag = false;//***改成这种写法....不要使用return.因为您将读数据的操作也放在这里了,而测试数据已不满足就return的话,可能会导致数据没有读完而报RE
}
double h = sqrt(d*d - y*y);
p[i].l = x - h;
p[i].r = x + h;
}
}
bool cmp(tt a, tt b){
if( b.r - a.r > 10e-7){
return true;
}
if(abs(a.r - b.r) < 10e-7 && ( b.l - a.l > 10e-7)){
return true;
}
return false;
}
void work(){
if( d == -1){
printf("-1\n");
return ;
}
sort(p+1,p+1+n,cmp);
int ans = 0;
double last = -10000.0;
int i;
for(i = 1 ; i <= n ; ++i){
if(p[i].l <= last){
if(p[i].r <= last){//***这个一定要有,用于处理(-1,5)、(1,3)这种情况
last = p[i].r;
}
continue;
}
ans++;
last = p[i].r;
}
printf("%d\n",ans);
}
int main(){
int counter = 1;
while(scanf("%d%d",&n,&d)!=EOF,n||d){
printf("Case %d: ",counter++);
init();
if(!flag){
printf("-1\n");
}else{
work();
}
}
return 0;
}
(Relax 1.6)POJ 1328 Radar Installation(利用数据有序化进行贪心选择)
最新推荐文章于 2020-10-10 10:09:01 发布
本文提供了一道来自POJ平台的题目解答思路与代码实现。该题涉及通过输入圆的直径和坐标来计算能够覆盖所有圆的最小数量的区间。文章包含完整的C++代码示例,并介绍了关键算法步骤。

748

被折叠的 条评论
为什么被折叠?



