NYOJ 287

题意:有一条海岸线(无限长),在这条线的两边有n个小岛,分别给出的是小岛的坐标,还有雷达的半径,然后问最少有多少个雷达,每个雷达可以看成是一个圆,使得所有的岛都被涵盖!!!如果不能被涵盖,那么就输出“-1”;




#include

#include
#include
#include
#include
#include
using namespace std;
struct node {
    double st_x;
    double ed_x;
};
node point[1001];


bool cmp(node a,node b) {
    if(a.st_x==b.st_x) {
        return a.ed_x>b.ed_x;
    } else {
        return a.st_x     }
}
int main() {
    int n;
    int t=0;
    double Radius;
    double x,y;
    while(~scanf("%d%lf",&n,&Radius)) {
        if(n==0&&Radius==0) {
            break;
        }
        bool flag=false;
        for(int i=0; i             scanf("%lf%lf",&x,&y);
            if(abs(y)>Radius) {
                flag=true;
                continue;
            }
            double dis=sqrt(Radius*Radius-y*y);
            point[i].st_x=x-dis;
            point[i].ed_x=x+dis;
        }
        if(flag) {
            printf("Case %d: -1\n",++t);
            continue;

        }


//用冒泡排序会TLE

//        for(int i=0; i //            for(int j=i+1; j //                if(point[i].st_x>point[j].st_x) {
//                    swap(point[i],point[j]);
//                } else {
//                    if(point[i].st_x==point[j].st_x) {
//                        if(point[i].ed_x //                            swap(point[i],point[j]);
//                        }
//                    }
//                }
//            }

//        }


        sort(point,point+n,cmp);
//        for(int i=0;i //            printf("%lf  %lf\n",point[i].st_x,point[i].ed_x);
//        }
        int ans=1;
        double tmp=point[0].ed_x;
        for(int i=0; i             if(point[i].ed_x                 tmp=point[i].ed_x;
            }
            if(tmp                 ans++;
                tmp=point[i].ed_x;
            }
        }
        printf("Case %d: %d\n",++t,ans);
    }
    return 0;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部