POJ 1328 Radar Installation
2013-05-18 19:41
330 查看
#include<iostream> #include<cmath> #include<algorithm> using namespace std; int n,d,ans; struct point { int x,y; }p[1010]; bool operator < (const point &a,const point &b) { return a.x<b.x; } bool operator == (const point &a,const point &b) { return (a.x==b.x)&&(a.y==b.y); } double getx(point a) { return a.x+sqrt(double(d*d-a.y*a.y)); } void f() { int i; double t,temp; t=getx(p[0]);ans=1; for(i=1;i<n;i++) { temp=getx(p[i]); if(p[i].x<t && t>temp) t=temp; else if(p[i].y*p[i].y+(t-p[i].x)*(t-p[i].x)<=d*d); else { ans++;t=temp; } } } int main() { int i,c=1,ok; while(cin>>n>>d && (n||d)) {ok=1; for(i=0;i<n;i++) { cin>>p[i].x>>p[i].y; if(p[i].y>d) ok=0; } cout<<"Case "<<c++<<": "; if(!ok) { cout<<-1<<endl;continue; } sort(p,p+n); f(); cout<<ans<<endl; } return 0; }
相关文章推荐
- poj 1328 Radar Installation 贪心
- POJ_1328_Radar Installation_贪心
- POJ:1328 Radar Installation (贪心)
- poj1328--Radar Installation
- POJ 1328 Radar Installation
- poj1328 Radar Installation
- POJ1328-贪心-区间选点问题
- poj 1328 Radar Installation(nyoj 287 Radar):贪心
- poj 1328 Radar Installation
- poj 1328 Radar Installation
- poj 1328 Radar Installation
- poj 1328
- POJ 1328 Radar Installation 贪心算法
- 1328 poj Radar Installation
- POJ 1328 Radar Installation 区间贪心
- poj1328 Radar Installation(贪心)
- poj 1328(贪心)
- POJ 1328 Radar Installation (贪心,区间选点问题)
- POJ-1328(Greedy,Vector,Sort,Iterator)
- POJ 1328 Radar Installation(经典贪婪)