hrbust 1414 (贪心)

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>

typedef struct Node
{
    double l;
    double r;
    bool operator < (const Node & a) const
    {
        return l < a.l;
    }
}Qstr;
Qstr q[1500];

using namespace std;

int main(void)
{
    int n;
    int d;
    int res;
    int kase = 0;

    while (scanf("%d%d", &n, &d), (n||d))
    {
        int tt = 0;
        int x, y;
        kase++;
        res = 1;

        for (int i=0; i<n; i++)
        {
            scanf("%d%d", &x, &y);
            if (tt < y)
            {
                tt = y;
            }
            q[i].l = x - sqrt(d*d - y*y);
            q[i].r = x + sqrt(d*d - y*y);
        }

        if (tt > d)
        {
            printf("Case %d: %d\n", kase, -1);
        }
        else
        {
            sort(q, q+n);

            double v = q[0].r;

            for (int i=0; i<n; i++)
            {
                if (q[i].l > v)
                {
                    res++;
                    v = q[i].r;
                }
                if (q[i].r < v)
                {
                    v = q[i].r;
                }
            }
            printf("Case %d: %d\n", kase, res);
        }
    }
    return 0;
}

 

posted @ 2013-03-13 20:00  尔滨之夏  阅读(248)  评论(0编辑  收藏  举报