poj 1328 Radar Installation
来源:互联网 发布:小站雅思mac 编辑:程序博客网 时间:2024/05/23 17:18
题意:平面上有一些点,你需要在x轴上添加一些半径为d的圆,使得所有点都在圆的范围内,求最少添加圆的数量。
思路:贪心。对每个点,计算圆能把它包含在内的最大横坐标,对它排序、然后按顺序检查一遍就好了。
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <map>#include <vector>#include <set>#include <string>#include <math.h>using namespace std;const double eps=1e-8;inline double fabs(double x){ if(x<0)x=-x; return x;}struct Node{ int x,y; double a; bool operator<(const Node& t)const{ return a<t.a; }};Node node[1010];int n;int d;inline bool judge(double x,double y,double radar){ if( (double)d*d >=fabs(x-radar)*fabs(x-radar)+y*y ){ return 1; } return 0;}int main(){ int cas=0; while(cin>>n>>d){ cas++; if(n==0&&d==0)break; bool ok=1; for(int i=0;i<n;i++){ scanf("%d%d",&node[i].x,&node[i].y); if(node[i].y>d)ok=0; if(ok)node[i].a=node[i].x+sqrt(d*d-node[i].y*node[i].y); } if(!ok){ printf("Case %d: ",cas); cout<<-1<<endl; continue; } sort(node,node+n); int ans=0; for(int i=0;i<n;){ double radar=node[i].a; ans++; i++; while(judge(node[i].x,node[i].y,radar)&&i<n){ i++; } } printf("Case %d: ",cas); cout<<ans<<endl; } return 0;}
0 0
- POJ 1328 "Radar Installation"
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- 1328 poj Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- POJ 1328 Radar Installation
- poj 1328 Radar Installation
- POJ-1328-Radar Installation
- poj 1328 Radar Installation
- POJ 1328 Radar Installation
- 各种问题的理解
- Codeforces Problem499A - Watching a movie
- win7环境下完全卸载、安装SQL Server2005详细教程
- 从调用printf()到显示器上看到字符串
- dotNet测试之三-------UFT API测试
- poj 1328 Radar Installation
- Storm集群安装2
- 线程返回建议使用_endthreadex()
- iOS压缩图片大小
- C++标准库---已序区间算法之一binary_search()&includes()
- 二十岁出头的时候,也许你一无所有,但你拥有者一切。
- 《数据结构》第4章 字符串和多维数组 知识点总结导图
- matlab 图片序列 生成 avi视频
- CSS属性之表格(Table)