NYOJ 287
来源:互联网 发布:学javascript需要什么基础 编辑:程序博客网 时间:2024/05/29 18:50
题意:有一条海岸线(无限长),在这条线的两边有n个小岛,分别给出的是小岛的坐标,还有雷达的半径,然后问最少有多少个雷达,每个雷达可以看成是一个圆,使得所有的岛都被涵盖!!!如果不能被涵盖,那么就输出“-1”;
#include<iostream>
#include<cstdio>#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
struct node {
double st_x;
double ed_x;
};
node point[1001];
bool cmp(node a,node b) {
if(a.st_x==b.st_x) {
return a.ed_x>b.ed_x;
} else {
return a.st_x<b.st_x;
}
}
int main() {
int n;
int t=0;
double Radius;
double x,y;
while(~scanf("%d%lf",&n,&Radius)) {
if(n==0&&Radius==0) {
break;
}
bool flag=false;
for(int i=0; i<n; i++) {
scanf("%lf%lf",&x,&y);
if(abs(y)>Radius) {
flag=true;
continue;
}
double dis=sqrt(Radius*Radius-y*y);
point[i].st_x=x-dis;
point[i].ed_x=x+dis;
}
if(flag) {
printf("Case %d: -1\n",++t);
continue;
}
//用冒泡排序会TLE
// for(int i=0; i<n; i++) {// for(int j=i+1; j<n; j++) {
// if(point[i].st_x>point[j].st_x) {
// swap(point[i],point[j]);
// } else {
// if(point[i].st_x==point[j].st_x) {
// if(point[i].ed_x<point[j].ed_x) {
// swap(point[i],point[j]);
// }
// }
// }
// }
// }
// for(int i=0;i<n;i++){
// printf("%lf %lf\n",point[i].st_x,point[i].ed_x);
// }
int ans=1;
double tmp=point[0].ed_x;
for(int i=0; i<n; i++) {
if(point[i].ed_x<tmp) {
tmp=point[i].ed_x;
}
if(tmp<point[i].st_x) {
ans++;
tmp=point[i].ed_x;
}
}
printf("Case %d: %d\n",++t,ans);
}
return 0;
}
0 0
- NYOJ 287
- NYOJ 287 Radar
- radar nyoj 287
- nyoj 287 Radar
- NYOJ-287 Radar
- NYOJ 287 Radar
- nyoj 287(区间覆盖)
- NYOJ 287 blockhouses
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- NYOJ
- 32位系统无法运行64位系统安装文件
- Gson简要使用笔记
- Hibernate 之 Persistence
- 数据库优化方案(一)
- linux抓包工具tcpdump的使用
- NYOJ 287
- 深入剖析Spring Web源码(三) - Spring Web MVC工作流
- 查看oracle数据库的连接数以及用户
- void main(void)用法
- XP系统,安卓手机搜不到热点,怎么解决
- Keil中常见的几种警告
- JS字符串变成方法名 及 window["s"] 的使用
- TextArea的值中有换行时的问题
- Live Resize of Logical Volume in RHEL/CentOS