码迷,mamicode.com
首页 > 其他好文 > 详细

Uva 2319

时间:2016-07-28 14:00:08      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享

理解:区域覆盖。假设该点在勘测半圆的边缘,求出与该点可在一个半圆的坐标范围l,r,然后,for 一次判断

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
struct  Point
{
    double l,r;
} p[1005];
int cmp(Point a,Point b)//排序的规则由main函数最后的for
{
    if(a.l!=b.l)//必须由右侧为主要,
       return a.l<b.l;
     return a.r>b.r;
}
int main()
{
    int n,d;
    int ct=1;
    while(cin>>n>>d&&(n+d))
    {
        bool flag=0;
        for(int i=0; i<n; i++)
        {
            int x,y;
            cin>>x>>y;
            if(y>d)
                flag=1;
            else
            {
                p[i].l=x+sqrt(d*d-y*y);
                p[i].r=x-sqrt(d*d-y*y);
            }
        }
        if(flag)
            {cout<<"Case "<<ct++<<": -1"<<endl;
            continue;}
        sort(p,p+n,cmp);
        double temp=p[0].l;
        int ans=1;
        for(int i=1; i<n; i++)
        {
            if(p[i].r<=temp)//temp是最远的 即和最远的可以在一个半圆 
                continue;
            else
            {
                ans++;
                temp=p[i].l;
            }

        }
        cout<<"Case "<<ct++<<": "<<ans<<endl;
    }


}

  

Uva 2319

标签:

原文地址:http://www.cnblogs.com/sxy-798013203/p/5714378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!