木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java3年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql4年进入店铺

POJ 1328 Radar Installation

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,d,ans;
struct point
{
    int x,y;
}p[1010];
bool operator < (const point &a,const point &b)
{
    return a.x<b.x;
}
bool operator == (const point &a,const point &b)
{
    return (a.x==b.x)&&(a.y==b.y);
}
double getx(point a)
{
    return a.x+sqrt(double(d*d-a.y*a.y));
}
void f()
{
    int i;
    double t,temp;
    t=getx(p[0]);ans=1;
    for(i=1;i<n;i++)
    {
        temp=getx(p[i]);
        if(p[i].x<t && t>temp)
            t=temp;
        else if(p[i].y*p[i].y+(t-p[i].x)*(t-p[i].x)<=d*d);
        else
        {
            ans++;t=temp;
        }
    }
}
int main()
{
    int i,c=1,ok;
    while(cin>>n>>d && (n||d))
    {ok=1;
        for(i=0;i<n;i++)
        {
            cin>>p[i].x>>p[i].y;
            if(p[i].y>d) ok=0;
        }
        cout<<"Case "<<c++<<": ";
        if(!ok)
        {
            cout<<-1<<endl;continue;
        }
        sort(p,p+n);
        f();
        cout<<ans<<endl;
    }
    return 0;
}

posted @ 2013-05-18 19:41  C语言程序  阅读(260)  评论(0编辑  收藏  举报
木其网络科技专业程序员代写http://www.xmsydw.com
程序员学历擅长经验网店链接
apenny硕士ASP.NET PHP 电子 通信设计 图像 编程 网络5年进入店铺
zheng_qianqian本科C语言 C++面向对象 Java3年进入店铺
guoguanl本科Java Web项目 JSP Hibernate Struts Mysql4年进入店铺