POJ1328 radar installation (Greedy)
来源:互联网 发布:java的构造方法 编辑:程序博客网 时间:2024/05/16 05:11
//主要是以岛为圆心画圆求区间,还有就是区间交并的问题#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int n,d,cas;struct node{ double x,y; double l,r;}p[1009];bool cmp(node a,node b){ //if(fabs(a.l-b.l)<1e8) return a.r<b.r; return a.l<b.l;}int main(){ while(scanf("%d%d",&n,&d)){ if(!(n+d)) return 0; double mx=0; for(int i=0;i<n;i++){ scanf("%lf%lf",&p[i].x,&p[i].y); mx=max(mx,p[i].y); } if(mx>d){ printf("Case %d: -1\n",++cas); continue; } for(int i=0;i<n;i++){ p[i].l=p[i].x-sqrt(d*d-p[i].y*p[i].y); p[i].r=p[i].x+sqrt(d*d-p[i].y*p[i].y); } sort(p,p+n,cmp); int cnt=1; double r=p[0].r; for(int i=1;i<n;i++){ if(p[i].l>r){ cnt++;r=p[i].r; } else if(p[i].r<r)//不能反了,否则i这点有可能没覆盖到 r=p[i].r; } printf("Case %d: %d\n",++cas,cnt); } return 0;}
0 0
- POJ1328 radar installation (Greedy)
- 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
- 【POJ1328】Radar Installation 贪心
- POJ1328 Radar Installation 贪心
- hdu2476 区间DP
- ACM OJ Hrbeu 1040 Compromise ||POJ 2250
- C#,物以“类”聚
- CentOS 6.5 配置SVN
- Ubuntu 14.04 中安装和配置 Java JDK
- POJ1328 radar installation (Greedy)
- 经典算法-算术表达式求值
- VMware中ubuntu忘记密码的解决办法
- 接口与抽象类
- Debian-7.6下升级glibc至2.15
- 红黑树,B树,B+树,B-树 理解
- 【Unity3D】Unity3D默认的快捷键
- 第十四章 14.4节练习
- HDU 3397——Sequence operation(线段树,区间染色+区间异或+区间合并)