nyist 287 Redar

题大意:

给你n 和r;r表示最大半径不能超过这个数

后面给定n个点的坐标,y 大于零,

输出如果不能全部覆盖输出  -1 

一开始还以为只要有一个满足就输出-1  结果我错了

这是一道区间选点问题

 

 

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=1010;
typedef struct x_y
{
    double x,y;
}X_Y;
X_Y a[N];
int fun(X_Y a,X_Y b)
{
    if(a.x<b.x) return 1;
    else return 0;
}
int main()
{
    int n,r;
    int t = 1;
    while(1)
    {
        double b[N];
        cin>>n>>r;
        if(n==0&&r==0)  break;
        double x1;
        int i,count=1;
        for( i = 0; i < n; i++)
        {
        cin>>x1>>b[i];
        double len = sqrt((r*r)-(b[i]*b[i]));
        a[i].x = x1 - len;
        a[i].y = x1 + len;
        }
        int flag = 1;
        for( i = 0; i < n; i++)
           if(b[i] > r)
           {
              cout<<"Case "<<t<<": -1\n";
               flag = 0;
               break;
           }

        if(flag)
        {
            sort(a,a+n,fun);
            double yy = a[0].y;
            for( i = 1; i < n; i++ )
                if(a[i].x>yy)
                {
                   count++;
                    yy = a[i].y;
                }
                else
                {
                    if(a[i].y<yy)
                       yy = a[i].y;
                }
                cout<<"Case "<<t<<": "<<count<<"\n";
        }
        t++;

    }
    return 0;

}

posted @ 2012-11-26 21:05  heity  阅读(124)  评论(0编辑  收藏  举报