您的位置:首页 > 其它

POJ 1328 Radar Installation

2013-05-18 19:41 330 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: