POJ 1328.Radar Installation
来源:互联网 发布:淘宝代运营 编辑:程序博客网 时间:2024/06/05 22:59
题目:http://poj.org/problem?id=1328
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string.h>using namespace std;struct PAIR{double left;double right;bool vis;};bool cmp(PAIR a, PAIR b){return a.right<b.right;}int main(){int n,d;int Case = 0;while(cin>>n>>d){if(n==0)break;Case++;vector<PAIR> pairs;bool flag = false;for(int i = 0; i < n; i++){int x,y;cin>>x>>y;if(y>d||d<0)flag = true;PAIR tmp;tmp.left = (double)x - sqrt((double)d*d-(double)y*y);tmp.right = (double)x + sqrt((double)d*d-(double)y*y);tmp.vis = false;pairs.push_back(tmp);}getchar(); getchar();sort(pairs.begin(),pairs.end(),cmp);int m = 0;for(vector<PAIR>::iterator it = pairs.begin(); it != pairs.end(); it++){if(it->vis==false){it->vis = true;for(vector<PAIR>::iterator itt = pairs.begin(); itt != pairs.end(); itt++){if(itt->left<=it->right&&itt->vis==false){itt->vis = true;}}m++;}}if(flag==false)cout<<"Case "<<Case<<": "<<m<<endl;else cout<<"Case "<<Case<<": -1"<<endl;}}总结:
刚看完题感觉没思路, 看过别人的解题思路后才知道用贪心算法. 做每个点为圆心的半径为d的圆, 记录交于x轴的左右两点. 设有AB两岛, 若B岛的左点在A岛的左右两点间, 则AB两岛共一个雷达站.
阅读全文
0 0
- poj 1328.Radar Installation
- POJ 1328.Radar Installation
- POJ 1328.Radar Installation
- solution of POJ: 1328.Radar Installation
- POJ 1328 "Radar Installation"
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ Radar Installation
- POJ 1328 Radar Installation
- 1328 poj Radar Installation
- poj 1328 Radar Installation
- POJ 1238 Radar Installation
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- POJ 1382 Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- Python学习笔记-17.09.20
- mxnet-Gluon(一):mxnet-Gluon 入门
- win10 Apache+PHP安装与环境配置
- 吴佳明(普空):LVS在大规模网络环境中的应用
- J2EE中基于监听方式的事件处理机制
- POJ 1328.Radar Installation
- 使用zip压缩文件方式安装mysql 5.7
- QT如何捕获全局的键盘事件?
- UML图
- 死锁
- spring在任何地方使用request
- awt包里的ColorSpace类
- PHP常用的一些公共函数(持续更新)
- url传中文乱码问题