zoukankan      html  css  js  c++  java
  • 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;
    }
    

  • 相关阅读:
    002-mybatis主配置文件
    001-mybatis框架
    mybatis学习
    tcp连接与释放
    浏览器输入url的全过程
    设备
    读写分离(三)
    读写分离(二)
    读写分离(一)
    主从复制(三)
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218254.html
Copyright © 2011-2022 走看看