ZOJ-1360 Radar Installation

本文介绍了一个针对雷达安装问题的优化算法。该算法旨在通过合理的雷达布局来覆盖尽可能多的海上岛屿,具体步骤包括计算每个岛屿的覆盖范围、采用快速排序算法进行区间合并,并最终确定最少的雷达安装数量。

Radar Installation

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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.


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


先算出所有的岛屿可以覆盖的区域,然后在交点上建立雷达,在向后面扩展结果时,选取重叠区域中右边区域最小的作为雷达的位置。


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

struct node {
	double x1;
	double x2;
};

void QuickSort(struct node *, int , int);
int process(struct node *, int, int);
int compare(struct node, struct node);

int main()
{
	int n, i, j, count = 0, total, flag;
	double dis, start, d, x, y;
	struct node pos[1000];
	while(scanf("%d%lf", &n, &d)) {
		count++;
		if(n == 0 && d == 0) {
			break;
		}
		flag = 1;
		for(i = 0; i < n; i++) {
			scanf("%lf%lf", &x, &y);
			if(flag) {
				dis = d*d - y*y;
				if(dis < 0) {
					flag = 0;
				} else {
					pos[i].x1 = x-sqrt(dis);
					pos[i].x2 = x+sqrt(dis);
				}
			}
		}
		printf("Case %d: ", count);
		if(flag == 0) {
			printf("-1\n");
		} else {
			QuickSort(pos, 0, n-1);
			total = 1;
			start = pos[0].x2;
			for(i = 1; i < n; i++) {
				if(pos[i].x1-start > 0) {
					total++;
					start = pos[i].x2;
				} else {
					if(pos[i].x2 < start) {
						start = pos[i].x2;
					}
				}
			}
			printf("%d\n", total);
		}
		getchar();
	}
	return 0;
}

void QuickSort(struct node *array, int s, int e)
{
	int k;
	if(s < e) {
		k = process(array, s, e);
		QuickSort(array, s, k-1);
		QuickSort(array, k+1, e);
	}
}

int process(struct node *array, int i, int j)
{
	struct node temp;
	temp = array[i];
	while(i < j) {
		while(i < j && compare(array[j], temp) >= 0) {
			j--;
		}
		array[i] = array[j];
		while(i < j && compare(array[i], temp) <= 0) {
			i++;
		}
		array[j] = array[i];
	}
	array[i] = temp;
	return i;
}

int compare(struct node n1, struct node n2)
{
	if(n1.x2 < n2.x2) {
		return -1;
	} else {
		return 1;
	}
}



【最优潮流】直流最优潮流(OPF)课设(Matlab代码实现)内容概要:本文档主要围绕“直流最优潮流(OPF)课设”的Matlab代码实现展开,属于电力系统优化领域的教学与科研实践内容。文档介绍了通过Matlab进行电力系统最优潮流计算的基本原理与编程实现方法,重点聚焦于直流最优潮流模型的构建与求解过程,适用于课程设计或科研入门实践。文中提及使用YALMIP等优化工具包进行建模,并提供了相关资源下载链接,便于读者复现与学习。此外,文档还列举了大量与电力系统、智能优化算法、机器学习、路径规划等相关的Matlab仿真案例,体现出其服务于科研仿真辅导的综合性平台性质。; 适合人群:电气工程、自动化、电力系统及相关专业的本科生、研究生,以及从事电力系统优化、智能算法应用研究的科研人员。; 使用场景及目标:①掌握直流最优潮流的基本原理与Matlab实现方法;②完成课程设计或科研项目中的电力系统优化任务;③借助提供的丰富案例资源,拓展在智能优化、状态估计、微电网调度等方向的研究思路与技术手段。; 阅读建议:建议读者结合文档中提供的网盘资源,下载完整代码与工具包,边学习理论边动手实践。重点关注YALMIP工具的使用方法,并通过复现文中提到的多个案例,加深对电力系统优化问题建模与求解的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值