Radar Installation(1328)

来源:互联网 发布:浙江义乌淘宝大学 编辑:程序博客网 时间:2024/06/07 20:38

大致题意:给定一些点和固定半径的圆, 圆心都在x轴上, 问至少要多少个圆才能将上面的点都包括在里面

方法:按照能包括这些点左边的圆心排序,然后从左向右贪心。

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;struct s{    double x, y, o;    bool operator < (const s &a) const{        return o < a.o;    }}pp[1100];int n, m, st;bool vis[1100];bool judge(){    int i;    for(i = 1; i <= n; i++)        if(!vis[i]){            st = i;            return true;        }    return false;}int main(){    int i, cas;    cas = 0;    while(scanf("%d%d", &n, &m) == 2){        if(!n && !m)            break;        memset(vis, 0, sizeof(vis));        int flag = 0;        for(i = 1; i <= n; i++){            scanf("%lf%lf", &pp[i].x, &pp[i].y);            if(pp[i].y > m)                flag = 1;            pp[i].o = pp[i].x + sqrt(m*m-pp[i].y*pp[i].y);        }        printf("Case %d: ", ++cas);        if(flag){            printf("-1\n");            continue;        }        sort(pp+1, pp+1+n);        int ans = 0;        while(judge()){            ans ++;            vis[st] = 1;            for(i = st+1; i <= n; i++){                if((pp[i].x-pp[st].o)*(pp[i].x-pp[st].o) + pp[i].y*pp[i].y <= m*m)                    vis[i] = 1;            }        }        printf("%d\n", ans);    }    return 0;}

0 0