您的位置:首页 > 其它

C题

2015-08-10 10:16 218 查看
C - C
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescriptionAssume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x<tex2html_verbatim_mark> - y<tex2html_verbatim_mark>coordinates.
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
struct node
{
double l,r;
};
node a[1010];
int cmp(node a,node b)
{
return a.l<b.l;
}
int main()
{
int n,d;
int x,y,f,t;
int s=0;
while(cin>>n>>d&&n&&d)
{
f=1;
t=1;
s++;
for(int i=0; i<n; i++)
{
cin>>x>>y;
if(y>d)f=0;
else
{
a[i].l=(double)x-sqrt((double)d*d-y*y);
a[i].r=(double)x+sqrt((double)d*d-y*y);
}
}
if(f==0)
{
cout<<"Case "<<s<<": -1"<<endl;
continue;
}
sort(a,a+n,cmp);
double p=a[0].r;
for(int i=1; i<n; i++)
{

if(a[i].r<p)
p=a[i].r;
else if(p<a[i].l)
{
p=a[i].r;
t++;
}
}
cout<<"Case "<<s<<": "<<t<<endl;

}
return 0;
}
View Code

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: