Radar Installation 贪心 hoj
2012-08-05 13:05
351 查看
/*这道贪心挺不错的.首先预处理出每个点对应的雷达极限位置. 然后就是区间覆盖的贪心揭发.先进行排序,. 开始时以第一个点的右位置为标准,当某一个点的左边大于他的时候,更新标准,ans++. 当某点的右位置小于他的时候,更新标准即可.*/ #include <stdio.h> #include <cmath> #include <iostream> #include <algorithm> struct point { double l,r; } a[1010]; bool cmp(struct point a,struct point b) { if(a.l!=b.l) return a.l<b.l; } using namespace std; int main() { int n; double d,x,y; int cases=1; while(scanf("%d%lf",&n,&d)==2&&(n+d)) { bool flag=false; for(int i=0; i<n; i++) { scanf("%lf%lf",&x,&y); if(y>d) flag=true; else { a[i].l=x-sqrt(d*d-y*y); a[i].r=x+sqrt(d*d-y*y); } } if(flag) printf("Case %d: -1\n",cases++); else { sort(a,a+n,cmp); int ans=1; int t=a[0].r; for(int i=1; i<n; i++) { if(a[i].l>t) { t=a[i].r; ans++; } if(a[i].r<t) t=a[i].r; } printf("Case %d: %d\n",cases++,ans); } } return 0; }
相关文章推荐
- 【hoj】2160 bin packing 二分、贪心
- HOJ1062 贪心+优先队列
- hoj 2430 Counting the algorithms(树状数组,贪心)
- HOJ 1262 贪心 ------ 过河问题
- HOJ 1597 find the nth digit(贪心)
- HOJ 3287 Cables(贪心)
- HOJ P-2244 Get the Colors(模拟+贪心)
- 【hoj】2160 bin packing 二分、贪心
- HOJ 2143 - Songs(贪心)
- HOJ 2430——Counting the algorithms(树状数组+贪心)
- (简单) 搜索 最短路 HOJ 1121 Erdos Numbers
- hdu 5360 Hiking (贪心+优先队列)
- HDU-5813-Elegant Construction【多校2016】【贪心】
- Best Cow Line POJ - 3617 【贪心】
- 搜索 HOJ 1114 Frame Stacking
- Codeforces 437C The Child and Toy( 贪心)
- 文章标题 HDU 1009 : FatMouse' Trade(贪心)
- uva11729(贪心,蓝书第2页)
- [数论] HOJ 1356 Prime Judge Miller Rabin+快速幂
- noip1999 旅行家的预算 (贪心)