POJ1328-Radar Installation(贪心)

Description
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d.

We use Cartesian coordinate system, defining the coasting is the x-axis. The sea side is above x-axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x-y coordinates.

Figure A Sample Input of Radar Installations


Input
The input consists of several test cases. The first line of each case contains two integers n (1<=n<=1000) and d, where n is the number of islands in the sea and d is the distance of coverage of the radar installation. This is followed by n lines each containing two integers representing the coordinate of the position of each island. Then a blank line follows to separate the cases.

The input is terminated by a line containing pair of zeros
Output
For each test case output one line consisting of the test case number followed by the minimal number of radar installations needed. "-1" installation means no solution for that case.
Sample Input
3 2
1 2
-3 1
2 1

1 2
0 2

0 0
Sample Output
Case 1: 2

Case 2: 1

出处:優YoU http://user.qzone.qq.com/289065406/blog/1299228061

提示:简单的贪心
正确的算法是:要考虑把雷达站放到哪个位置使得包含雷达的区间最多!
写算法的时候要注意,按海岛的横坐标排序(纵坐标是跟随横坐标,但不能对排序构成任何影响)后,第一个雷达建立在区间的右端,然后依次判断每个区间的左端点,如果在最新建立的雷达右面,那么肯定需要一个雷达,而且也建在区间右端。如果左端点在雷达左面,这个时候要考虑区间的右端在雷达的左面还是右面,如果是右面,那雷达位置就不变,如果在左面,那现在的雷达是覆盖不了的,所以要把雷达放在该区间的右端点!因为这样同时不但能覆盖原来的岛,还能覆盖现在的岛

标准方法是把每个点的放置雷达的区间求出,然后按照区间排序。排好序后,从左至右看,当发现下一个区间的起始点大于前面所有区间的最小结束点的时候,答案加一。忽视前面走过的所有点后,对后面进行相同的操作(从左至右看,当发现下一个区间的起始点大于左边未被忽视的所有区间的最小结束点的时候,答案加一)。直到结束。但是这样做相对较难实现。


#include<iostream> 
#include<math.h> 
using namespace std; 

const int island_max=1000; 

int main(void) 
{ 
int i,j; 
double x[island_max],y[island_max]; 
double num,rad; 
for(;;) 
{ 
/*Input end*/ 
cin>>num>>rad; 
if(!(num&&rad))break; 

static int count=1; //记录case数目 

/*read in coordinate*/ 
bool flag=false; 
for(i=0;i<num;i++) 
{ 
cin>>x[i]>>y[i]; 
if(y[i]>rad) 
flag=true; 
} 

/*case fail*/ 
if(flag) 
{ 
cout<<"Case "<<count++<<": -1"<<endl; 
continue; 
} 

/*bubble sort*/ 
//这里由于y要随x连带排序,不能简单地使用 快排qsort 
double temp; 
for(i=0;i<num-1;i++) 
for(j=0;j<num-i-1;j++) 
if(x[j]>x[j+1]) 
{ 
temp=x[j]; 
x[j]=x[j+1]; 
x[j+1]=temp; 
temp=y[j]; 
y[j]=y[j+1]; 
y[j+1]=temp; 
} 

double left[island_max],righ[island_max]; //海岛圆在海岸线上的左右交点 
for(i=0;i<num;i++) 
{ 
left[i]=x[i]-sqrt(rad*rad-y[i]*y[i]); 
righ[i]=x[i]+sqrt(rad*rad-y[i]*y[i]); 
} 

int radar=1; 
for(i=0,temp=righ[0];i<num-1;i++) 
if(left[i+1]>temp) 
{ 
temp=righ[i+1]; 
radar++; 
} 
else if(righ[i+1]<temp) 
temp=righ[i+1]; 

cout<<"Case "<<count++<<": "<<radar<<endl; 
} 
return 0; 
} 


一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值