poj 1328 Radar Installation
2014-06-01 16:04
239 查看
#include <cstdio> #include <algorithm> #include <cmath> #define MAX_N 1100 using namespace std; pair<int,int> point[MAX_N]; pair<double,double> arr[MAX_N]; //input int n,d; //answer int ans; int cnt = 1; void solve(){ ans = 1; //对点按左端点进行整理 sort(arr,arr + n); //for(int i = 0;i < n;i++){ // printf("%lf %lf",arr[i].first,arr[i].second); // } double spos = arr[0].second; //最左点的最右距离 for(int i = 1;i < n; i++){ if (arr[i].first - spos > 1e-5) { ans++; spos = arr[i].second; }else{ if (arr[i].second - spos < 1e-5) //下个岛屿的最右坐标小于当前最右可被侦测坐标 { spos= arr[i].second; } } } } int main(){ //freopen("C:\in.txt","r",stdin); while(scanf("%d%d",&n,&d) != EOF){ int ok = 1; if(!n && !d) break; for(int i = 0;i < n;i++){ scanf("%d%d",&point[i].first,&point[i].second); if(point[i].second > d) ok = 0; } //如果只有一个点 // if(n == 1) {printf("Case %d: 1\n",cnt++); continue;} //将坐标系上的点转为x轴上的区间 for(int i = 0;i < n;i++){ double x = point[i].first,y = point[i].second; double len = sqrt((double)(d*d - y*y)); arr[i].first = x - len; arr[i].second = x + len; } if(ok == 0){ printf("Case %d: -1\n",cnt++); continue; }else{ solve(); printf("Case %d: %d\n",cnt++,ans); } } return 0; }
相关文章推荐
- Radar Installation POJ - 1328 (区间选点问题)
- POJ 1328 "Radar Installation"
- [POJ 1328] Radar Installation
- POJ1328 Radar Installation (区间选点问题,贪心)
- POJ 1328 Radar Installation
- POJ--1328:Radar Installation (贪心)
- POJ 1328 Radar Installation 贪心
- POJ 1328 解题报告
- poj 1328 Radar Installation 贪心
- POJ1328 贪心
- POJ 1328
- POJ1328-Radar Installation(贪心)
- D - Radar Installation POJ - 1328
- poj 1328 && uva 1193 && la 2519
- 【poj】1328 Radar Installation 快排+贪婪
- POJ1328——Radar Installation
- POJ 1328 Radar Installation
- poj1328
- POJ 1328
- POJ 1328 Radar Installation