外星人的供给站 (区间覆盖 t贪心)

/**
区间覆盖问题
分析: 每个点可以确定两个圆心 圆心的范围形成
一个区间 在这个区间上以任意一点画圆便可将此点
包含在内

如果有两个点所确定的区间相交了 说明这两个点可以用一个圆包含在内

即用一个区间的右端点与下一个区间的左短点相比较 所以
用后排的方式

(好像做过的这种题目差不多都是用的后排的方式)

*/

include<stdio.h>

include<math.h>

include

using namespace std;
struct node
{
double left;
double right;
};
bool cmp(node a,node b)
{
//if(a.left!=b.left)return a.left<b.left;
return a.right<b.right;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,r;
scanf("%d%d",&n,&r);
node yuanDian[n];
for(int i=0; i<n; i++)
{
int x,y;
scanf("%d%d",&x,&y);
yuanDian[i].left= x-sqrt(rr1.0-yy1.0);
yuanDian[i].right= x+sqrt(rr1.0-yy1.0);
// yuanDian[i].left=x;
// yuanDian[i].right=y;

    }
    sort(yuanDian,yuanDian+n,cmp);
    double max1=yuanDian[0].right;
    int count=1;
    for(int i=1; i<n; i++)
    {
        if(max1<yuanDian[i].left)///没有相交的点
        {
            count++;
            max1=yuanDian[i].right;
        }
    }
    printf("%d\n",count);
}
return 0;

}

posted @ 2016-05-24 12:35  -梦里不知身是客  阅读(153)  评论(0编辑  收藏  举报