【POJ】1328
来源:互联网 发布:工业3.0是什么知乎 编辑:程序博客网 时间:2024/05/22 19:47
http://poj.org/problem?id=1328
给定海岛个数、雷达半径以及各海岛坐标,求能覆盖所有海岛的最小雷达数。
以岛屿为圆心,以d为半径画圆,若圆与x轴无交点则输出-1,若存在交点,则计算出岛屿与x轴的交点坐标分别记为rad[i].st与rad[i].ed。
按照rad[i].ed升序排列,从左到右找雷达。
例如此时rad[i].ed为当前的最右边,对于下一个岛屿j,若rad[j].st < rad[i].ed,则不需要建立新的雷达。否则需要建立新的雷达。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int n,d,t;int Max_y;double len;int ans;bool vis[1005];struct Island{ int x; int y;}is[1005];struct Data{ double st,ed;}rad[1005];bool cmp(Data a,Data b){ return a.ed<b.ed;}int main(){ while (cin >> n >> d){ if (n==0) break; Max_y=0; for (int i=0;i<n;i++){ cin >> is[i].x >> is[i].y; Max_y=max(Max_y,is[i].y); } cout << "Case " << ++t << ": "; if (Max_y>d||d<0){ cout << "-1" << endl; continue; } for (int i=0;i<n;i++){ len=sqrt(1.0*d*d-is[i].y*is[i].y); rad[i].st=is[i].x-len; rad[i].ed=is[i].x+len; } sort(rad,rad+n,cmp); ans=0; memset(vis,false,sizeof(vis)); for (int i=0;i<n;i++){ if (!vis[i]){ vis[i]=true; for (int j=0;j<n;j++){ if (!vis[j]&&rad[j].st<=rad[i].ed){ vis[j]=true; } } ans++; } } cout << ans << endl; }}
阅读全文
0 0
- poj 1083 & poj 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ--1328
- poj-1328
- POJ 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ 1328
- poj 1328
- 网络与通信:网络其他问题
- OGG 12.2 模拟文件故障
- javaFX的几个新特性,让swing彻底过时
- <a>标签中href属性动作和onclick事件的区别以及传递this参数对象
- 题目1033:继续xxx定律
- 【POJ】1328
- 前端工程师是怎样一种职业
- python xpath介绍和新闻内容爬虫
- python包——好玩的wordcloud
- 一头坑进Redis之持久化 Snapshot和AOF说明
- 父类中访问子类成员
- 驱动模型
- 生产者与消费者模型(互斥锁)
- python 分页爬取