生活随笔
收集整理的這篇文章主要介紹了
【贪心】雷达问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目描述
張琪曼等人用時(shí)空雷達(dá)定位李旭琳所在的空間位置。如圖7.3所示,時(shí)空雷達(dá)裝在一條直線上,直線上方是空間海洋,每個(gè)人在空間海洋的位置就如同大海中的島嶼,這些人的位置已知,每一個(gè)雷達(dá)的掃描范圍是一個(gè)半徑為d的圓形區(qū)域,問(wèn)最少需要多少個(gè)雷達(dá)覆蓋所有的人(島嶼)。
?
輸入
輸入包括多組測(cè)試數(shù)據(jù),每組測(cè)試數(shù)據(jù)第一行為兩個(gè)整數(shù)n (1≤n≤1000) 和 d,即島嶼數(shù)和雷達(dá)掃描半徑。隨后n行每行兩個(gè)整數(shù)表示島嶼坐標(biāo)。每組測(cè)試數(shù)據(jù)以空行間隔,所有測(cè)試數(shù)據(jù)以0 0結(jié)束。
?
輸出
輸出最少需要安裝雷達(dá)數(shù),每組一行。若無(wú)解以-1表示。
?
樣例輸入
3 2
1 2
-3 1
2 1
1 2
0 2
0 0
樣例輸出
Case 1: 2
Case 2: 1
#include <iostream>
#include <
string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define rerange(i,a,b) for(int i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
pair<
double,
double>aa[
115];
int n,d;
void init(){}
void swap(
int&a,
int&
b){int tmp=
a;a=
b;b=
tmp;
}
bool cmp(pair<
double,
double>a,pair<
double,
double>
b){return a.second<
b.second;
}
void solve(){int cas=
0;while(cin>>n>>
d,n,d){bool flag=
true;double x,y;range(i,0,n-
1){cin>>x>>
y;if(!flag)
continue;if(y>
d){flag=
false;continue;}aa[i].first=(x-sqrt(d*d-y*
y));aa[i].second=(x+sqrt(d*d-y*
y));}cout<<
"Case "<<++cas<<
": ";if(!
flag){cout<<-
1<<
endl;continue;}sort(aa,aa+
n,cmp);double tmp=-
123845;
int ans=
0;range(i,0,n-
1)
if(tmp<
aa[i].first){++ans;tmp=
aa[i].second;}cout<<ans<<
endl;}
}
int main() {init();solve();return 0;
} View Code ?
轉(zhuǎn)載于:https://www.cnblogs.com/Rhythm-/p/9344574.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖
總結(jié)
以上是生活随笔為你收集整理的【贪心】雷达问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。