您的位置:首页 > 其它

UVALIVE 2519 Radar Installation 区间选点问题

2014-07-05 22:12 330 查看
#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
#define MAXN 1005
int gcd(int a, int b)
{
return a % b == 0 ? b : gcd(b, a % b);
}
int N,R;
bool vis[MAXN];
struct node
{
double l,r;
friend bool operator <(const node &a, const node &b)
{
if (a.r==b.r)return a.l<b.l;
return a.r<b.r;
}
}src[MAXN];
int main()
{
//freopen("sample.txt","r",stdin);
int kase=1;
while (scanf("%d%d",&N,&R)!=EOF)
{
if (N==0 && R==0) break;
bool found=false;
int x,y;
for (int i=0;i<N;i++)
{
scanf("%d%d",&x,&y);
if (y>R) found=true;
double t=sqrt((double)(R*R-y*y));
src[i].l=x-t;
src[i].r=x+t;
}
printf("Case %d: ",kase++);
if (found) printf("-1\n");
else
{
sort(src,src+N);
memset(vis,false,sizeof(vis));
int ans=0;
double tmp;
for (int i=0;i<N;i++)
{
if (vis[i]) continue;
ans++;
int j=i+1;
tmp=src[i].r;
while (j<N){
if (!vis[j] && src[j].l<=tmp) vis[j]=true; j++;
}

}
printf("%d\n",ans);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: