(Relax 1.6)POJ 1328 Radar Installation(利用数据有序化进行贪心选择)
2013-12-12 22:06
507 查看
/* * POJ_1328.cpp * * Created on: 2013年11月18日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1010; struct tt{ double l,r; }p[maxn]; int n,d; bool flag; void init(){ flag = true; int i; double x,y; for(i = 1 ; i <= n ; ++i){ scanf("%lf%lf",&x,&y); if(d < y){ flag = false;//***改成这种写法....不要使用return.因为您将读数据的操作也放在这里了,而测试数据已不满足就return的话,可能会导致数据没有读完而报RE } double h = sqrt(d*d - y*y); p[i].l = x - h; p[i].r = x + h; } } bool cmp(tt a, tt b){ if( b.r - a.r > 10e-7){ return true; } if(abs(a.r - b.r) < 10e-7 && ( b.l - a.l > 10e-7)){ return true; } return false; } void work(){ if( d == -1){ printf("-1\n"); return ; } sort(p+1,p+1+n,cmp); int ans = 0; double last = -10000.0; int i; for(i = 1 ; i <= n ; ++i){ if(p[i].l <= last){ if(p[i].r <= last){//***这个一定要有,用于处理(-1,5)、(1,3)这种情况 last = p[i].r; } continue; } ans++; last = p[i].r; } printf("%d\n",ans); } int main(){ int counter = 1; while(scanf("%d%d",&n,&d)!=EOF,n||d){ printf("Case %d: ",counter++); init(); if(!flag){ printf("-1\n"); }else{ work(); } } return 0; }
相关文章推荐
- (Relax 1.6)POJ 1323 Game Prediction(利用有序化数据进行贪心选择: 有m个人,每个人有n张牌,别人想方设法的让你输,求你能赢多少次)
- (贪心5.2.5)POJ 1862 Stripies(利用数据有序化来进行贪心选择)
- (贪心5.2.3)POJ 1065 Wooden Sticks(利用数据有序化来进行贪心选择)
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)
- (贪心5.2.1)UVA 10026 Shoemaker's Problem(利用数据有序化来进行贪心选择)
- (贪心5.2.6)URAL 1014 Product of Digits(利用数据有序化进行贪心选择)
- (贪心5.2.9)UVA 10020 Minimal coverage(利用数据有序化来进行贪心选择)
- (贪心5.2.2)UVA 10954 Add All(利用数据的有序化来进行贪心选择)
- (Relax 1.2)POJ 2586 Y2K Accounting Bug(贪心选择往往发生在极端处)
- poj 1328 Radar Installation (贪心选择性质,需要抽象出来才可以)
- POJ 1328 区间点选择 贪心
- 利用decode函数实现按不同的选择条件 对数据进行分组统计
- 已知一个几乎有序的数组,几乎有序是指,如果把数组排好顺序的话,每个元素移动的距离可以不超过k,并且k相对于数组来说比较小。请选择一个合适的排序算法针对这个数据进行排序。 给定一个int数组A,同时给定
- (贪心5.2.4)ZOJ 1360 Radar Installation(对有序化数据进行贪心选择)
- Android利用Fiddler进行网络数据 抓包
- 利用sqoop1.6对mysql和hive进行同步的问题
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- 利用临时变量对每个分组的数据进行累计
- (一般)POJ-1328 区间贪心,几何