poj1328
来源:互联网 发布:python 无穷大 编辑:程序博客网 时间:2024/06/08 02:09
这道题的解题思路是从一个岛屿出发,而不是从雷达出发,因为岛屿是静态的,而雷达则可以移动,可以根据岛屿的参数来寻则雷达,总结为区间的重叠性。
尤其要注意的是两个区间有重合的时候,右区间的更新问题,还有distance是负的状态,以及在x轴没有交点的状态。
#include <iostream>#include <vector>#include <utility>#include <math.h>#include <algorithm>using namespace std;typedef struct node{double lx;double rx;}Node;int cmp(Node point1,Node point2){return point1.lx<point2.lx?1:0;}int main(){int caseCount,distance,i,radar,count=0,flag=0;double x,y;Node point[1000];double lx,rx,last;cin >> caseCount >> distance;while(caseCount||distance){i=0;radar=1;flag=0;while (caseCount--){cin >> x >> y;if((distance*distance-y*y<0)||distance<=0)continue;lx=x-sqrt(distance*distance-y*y);rx=x+sqrt(distance*distance-y*y);point[i].lx=lx;point[i++].rx=rx;flag=1;}if(flag){sort(point,point+i,cmp);last=point[0].rx;for (int j=1;j<i;j++){if(point[j].lx>last){radar++;last=point[j].rx;}else if(point[j].rx<last)last=point[j].rx;}++count;cout << "Case " << count << ": " << radar << endl; }cin >> caseCount >> distance;}return 0;}
- POJ1328
- poj1328
- POJ1328
- poj1328
- POJ1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- POJ1328
- POJ1328
- POJ1328
- poj1328
- POJ1328
- 在ubuntu 10.04.01TLS 中安装中文输入法
- P 123
- linux sort 命令详解
- service httpd does not support chkconfig
- C陷阱与缺陷笔记
- poj1328
- js通过事件获取页面元素对象-适用于IE、FireFox
- 线程相关问题
- asp.net gridview itemtemplate中控件事件获取行参数
- CF C. Students' Revenge
- C++面试题
- 提升Oracle所需的基础技能
- 模版+数据分离渲染方式的设计与实现
- JavaScript 设置Cookie