poj1328求解代码
时间: 2023-12-20 21:23:43 浏览: 37
以下是POJ1328求解的C++代码:
```
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1005;
struct Island{
double left, right;
}island[MAXN];
bool cmp(Island a, Island b){
return a.left < b.left;
}
int main(){
int n, d;
int count = 0;
while(cin >> n >> d && n){
count++;
bool flag = true;
for(int i=0; i<n; i++){
double x, y;
cin >> x >> y;
if(y > d) flag = false;
double len = sqrt(d*d - y*y);
island[i].left = x - len;
island[i].right = x + len;
}
if(!flag){
cout << "Case " << count << ": " << -1 << endl;
continue;
}
sort(island, island+n, cmp);
int ans = 1;
double pos = island[0].right;
for(int i=1; i<n; i++){
if(island[i].left > pos){
ans++;
pos = island[i].right;
}else{
pos = min(pos, island[i].right);
}
}
cout << "Case " << count << ": " << ans << endl;
}
return 0;
}
```
此题解析和代码请参考:[POJ 1328 Radar Installation](https://www.cnblogs.com/ECJTUACM-873284962/p/6286072.html)
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)