POJ1328 Radar Installation 贪心
来源:互联网 发布:网络教育哪家好考 编辑:程序博客网 时间:2024/05/16 09:12
原题:http://poj.org/problem?id=1328
思路:先将小岛按照横坐标排序,第一个雷达建立在第一个小岛区间的右端,然后依次判断每个区间的左端点,如果在新建的雷达右面,说明需要建立新的雷达,并且新的雷达位置为其右端点;如果左端点在雷达左面,考虑右端点的状态,如果右端点在雷达右边,雷达位置不变,如果在左面,把雷达的位置更新为此区间的右端点
#include<iostream>#include<cmath>#include<cstring>#include<cstdlib>using namespace std;const int maxn=1005;typedef struct{ double x; double y;}node;node st[maxn];int cmp(const void* a,const void* b){ return (*(node *)a).x>(*(node *)b).x?1:-1;}int main(){ int i; double num,rad; int count=1; while(cin>>num>>rad) { if(num==0&&rad==0) break; int flag=0; for(i=0;i<num;i++) { cin>>st[i].x>>st[i].y; if(st[i].y>rad) flag=1; } if(flag) { cout<<"Case "<<count++<<": -1"<<endl; continue; } qsort(st,num,sizeof(st[0]),cmp); double left[maxn],right[maxn]; //海岛圆在海岸线上的交点 for(i=0;i<num;i++) { left[i]=st[i].x-sqrt(rad*rad-st[i].y*st[i].y); right[i]=st[i].x+sqrt(rad*rad-st[i].y*st[i].y); } int cnt=1; double tmp; for(i=0,tmp=right[0];i<num-1;i++) { if(left[i+1]>tmp) { cnt++; tmp=right[i+1]; } else if(right[i+1]<tmp) { tmp=right[i+1]; } } cout<<"Case "<<count++<<": "<<cnt<<endl; } return 0;}
0 0
- POJ1328 Radar Installation 贪心
- POJ1328 Radar Installation 贪心
- 【贪心】POJ1328 Radar Installation
- poj1328 Radar Installation 贪心
- 【POJ1328】Radar Installation 贪心
- POJ1328 Radar Installation 贪心
- 贪心- poj1328 Radar Installation
- POJ1328 Radar Installation 贪心
- poj1328 Radar Installation 贪心
- poj1328 Radar Installation 贪心
- POJ1328 Radar Installation (贪心)
- POJ1328 Radar Installation(贪心)
- POJ1328 Radar Installation(贪心)
- 【贪心】[POJ1328]Radar Installation
- POJ1328-Radar Installation(贪心)
- ZOJ1360 POJ1328 Radar Installation, 贪心
- poj1328 Radar Installation(贪心)
- POJ1328--Radar Installation(贪心)
- 黑马程序员_java高新(四)_类加载器、动态代理
- Hibernate 二级缓存
- php常量及变量定义方法
- 数据结构栈C++简单实现
- 失败了一天啊!
- POJ1328 Radar Installation 贪心
- lua 解析 xml 文件,含内嵌
- CentOS安装SNMP
- Eclipse Kepler SR2 设置 每次打开选择工作区
- 黑马程序员_String类
- 静态成员变量和静态成员函数的定义
- 值初始化
- Linux命令
- Base64练习2