POJ1328 Radar Installation
来源:互联网 发布:iphone摄影曝光软件 编辑:程序博客网 时间:2024/05/17 04:09
点击打开题目描述
题目大意
在x轴上方有n个点,让你用圆心在x轴上,半径为d的圆覆盖这些点,求最小的圆的个数
典型的区间覆盖问题,运用勾股定理可以计算出海岸线上(x轴)能够覆盖到每一个点的区间(注意,区间边界可能是浮点数,就因为这个被卡了好久,QAQ)接下来的问题可以参考我的另一篇博客
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include<cmath>using namespace std;struct node{ double l,r;}a[1001];bool cmp(node x,node y){ if(x.r<y.r)return 1; if(x.r==y.r)if(x.l<y.l)return 1; return 0;}int getint(){ int num=0,flag=1;char c; while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1; while(c>='0'&&c<='9')num=num*10+c-48,c=getchar(); return num*flag;}int n,d,s;bool v[1001];int main(){ int i,x,y,o=0; bool p; n=getint(),d=getint(); while(n) { s=p=0;memset(v,0,sizeof v); for(i=1;i<=n;i++) { x=getint(),y=getint(); if(y*y>d*d)p=1; double hh=sqrt((d*d-y*y)*1.0); a[i].l=x-hh,a[i].r=x+hh; } if(p||d<0){printf("Case %d: -1\n",++o);goto hh;} sort(a+1,a+n+1,cmp); for(i=1;i<=n;i++) if(!v[i]) { double hh=a[i].r; s++; while(a[i].l<=hh)v[i]=1,i++; i--; } printf("Case %d: %d\n",++o,s); hh:; n=getint(),d=getint(); }}
阅读全文
2 0
- POJ1328 Radar Installation
- POJ1328 Radar Installation 贪心
- POJ1328----Radar Installation
- POJ1328:Radar Installation
- poj1328 Radar Installation
- poj1328--Radar Installation
- poj1328 Radar Installation
- POJ1328 Radar Installation
- POJ1328 &AOJ195 Radar Installation
- POJ1328 Radar Installation 贪心
- 【贪心】POJ1328 Radar Installation
- poj1328 Radar Installation 贪心
- poj1328--Radar Installation
- POJ1328-Radar Installation
- POJ1328 radar installation (Greedy)
- poj1328--Radar Installation
- 【POJ1328】Radar Installation 贪心
- POJ1328 Radar Installation 贪心
- POJ 2406 Power Strings——kmp求最短循环子串
- centos7.2安装VIM编辑软件及VIM命令大全
- GIT分布式版本控制
- Android之Debug运行项目一直卡在Debug界面(can't bind to local 8066 for debug)
- 拼多多陷信任危机:创业公司做明星还是做寿星?
- POJ1328 Radar Installation
- Java中for循环的2道经典练习题
- 只能在堆(栈)上创建的类
- 《慕课网玩转算法面试》笔记及习题解答2
- bootstrap fileinput 上传图片
- Efficient data transfer through zero copy
- 【NOIP2017提高A组模拟7.14】紧急撤离
- gradle标准配置文件build.gradle
- 正式开始学习java