poj1328(贪心)
来源:互联网 发布:mac给ios手机装 编辑:程序博客网 时间:2024/06/08 13:55
题意:假设海岸线是一条无限延伸的直线。陆地在海岸线的一侧,而海洋在另一侧。
题意:每一个小的岛屿是海洋上的一个点。雷达坐落于海岸线上,只能覆盖d距离,
题意:所以如果小岛能够被覆盖到的话,它们之间的距离最多为d。
题意:求出能够覆盖给出的所有岛屿的最少雷达数目。
分析:假设点A为某岛屿,求出在x轴上放雷达能覆盖A的圆心所在范围。如图,圆心在[L,R]之间
分析:就将问题转换为了贪心区间问题。
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespace std;#define N 1005struct Point{int x,y;}p[N];struct C{ double r,l; bool operator < (const C t)const{ return l<t.l; }}ro[N];int main(){ int n,d,ncase=0; while(scanf("%d%d",&n,&d)!=EOF,n){ for(int i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); int ok=1; printf("Case %d: ",++ncase); for(int i=0;i<n;i++){ if(p[i].y>d||p[i].y<-d){ok=0;break;} ro[i].r=1.0*p[i].x+sqrt(double(d*d-p[i].y*p[i].y)); ro[i].l=1.0*p[i].x-sqrt(double(d*d-p[i].y*p[i].y)); }if(ok){ int i,j,ans=1; sort(ro,ro+n); C temp=ro[0]; for(int i=1;i<n;i++){ if(temp.r<ro[i].l){ ans++; temp=ro[i]; }else if(temp.r>ro[i].r)temp=ro[i]; }printf("%d\n",ans); }else printf("-1\n"); } return 0;}
0 0
- poj1328(贪心)
- poj1328(区间贪心)
- poj1328 Radar Installation(贪心)
- POJ1328--Radar Installation(贪心)
- poj1328 Radar Installation(贪心)
- poj1328 Radar Installation(贪心)
- POJ1328-Radar Installation(贪心)
- POJ1328 Radar Installation(贪心)
- #POJ1328#Radar Installation(贪心)
- POJ1328 Radar Installation(贪心)
- Radar Installation(POJ1328, 贪心)
- POJ1328贪心
- POJ1328--贪心
- poj1328(贪心)
- poj1328 贪心
- poj1328 贪心
- poj1328 贪心
- poj1328贪心
- 复制一个文件
- 白话经典算法系列之十六 “基数排序”之数组中缺失的数字
- 微信移动应用接入开发, Android 授权微信登录获取openid,unionid等,score参数错误或者没有scope权限
- Map、Set、List、Queue、Stack的特点与用法2
- 【程序员养生】:养护肾脏
- poj1328(贪心)
- ThreadPoolExecutor JDK线程池
- 把一个类存放在硬盘,并通过代码读取类的信息,输出到屏幕上
- shell学习
- 关于iOS国际化(根据手机系统来切换语言) App支持多语言切换
- UIView显示图片
- 给多行文本添加 前标 1. 2. 3. 4. 5. 6. 7.
- NYOJ 60 谁获得了最高奖学金(结构体)
- 白话经典算法系列之十七 数组中只出现一次的数