hdu4723 How Long Do You Have to Draw 贪心

本文探讨了一种算法问题,即如何在两个水平线上各取若干点,并通过连线形成尽可能多的三角形,同时确保连线总长度最短。文章提供了解决方案及实现代码。

How Long Do You Have to Draw

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 322    Accepted Submission(s): 128


Problem Description
There are two horizontal lines on the XoY plane. One is y1 = a, the other is y2 = b(a < b). On line y1, there are N points from left to right, the x-coordinate of which are x = c1, c2, ... , cN (c1 < c2 < ... < cN) respectively. And there are also M points on line y2 from left to right. The x-coordinate of the M points are x = d1, d2, ... dM (d1 < d2 < ... < dM) respectively.
Now you can draw segments between the points on y1 and y2 by some segments. Each segment should exactly connect one point on y1 with one point on y2.
The segments cannot cross with each other. By doing so, these segments, along with y1 and y2, can form some triangles, which have positive areas and have no segments inside them.
The problem is, to get as much triangles as possible, what is the minimum sum of the length of these segments you draw?
 

Input
The first line has a number T (T <= 20) , indicating the number of test cases.
For each test case, first line has two numbers a and b (0 <= a, b <= 104), which is the position of y1 and y2.
The second line has two numbers N and M (1 <= N, M <= 105), which is the number of points on y1 and y2.
The third line has N numbers c1, c2, .... , cN(0 <= ci < ci+1 <= 106), which is the x-coordinate of the N points on line y1.
The fourth line has M numbers d1, d2, ... , dM(0 <= di < di+1 <= 106), which is the x-coordinate of the M points on line y2.
 

Output
For test case X, output "Case #X: " first, then output one number, rounded to 0.01, as the minimum total length of the segments you draw.
 

Sample Input
1 0 1 2 3 1 3 0 2 4
 

Sample Output
Case #1: 5.66
 


既然先要满足三角形最多,那么肯定是要把所有的点能连的都连起来,然后重点是最短线段长度,如图



黑线是已经连接的线,x和y是当前位置,下一条线有两种连接方法,即绿线和蓝线,c[x]->d[y + 1]和 d[y]->c[x + 1],因为c[x]->d[y + 1]较短,所以选这条,y到y + 1的位置上去,然后把这条线段累加上,如果蓝线较短的话则将x放到x + 1的位置上去,然后把这条线段累加上,注意初始化和最后的边界,每一步都这样择优,最后输出的线段长度和一定最小




#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>

using namespace std;

double c[100005], d[100005];

int main()
{
	int T, n, m, x, y;
	double a, b, h, len;
	scanf("%d", &T);
	for (int t = 1; t <= T; t++) {
		scanf("%lf%lf", &a, &b);
		h = fabs(a - b) * fabs(a - b);
		scanf("%d%d", &n, &m);
		for (int i = 0; i < n; i++)
			scanf("%lf", &c[i]);
		for (int i = 0; i < m; i++)
			scanf("%lf", &d[i]);
		x = y = 0;
		len = 0;
		while (x < n && y < m) {
			len += sqrt(h + fabs(c[x] - d[y]) * fabs(c[x] - d[y]));
			if (x == n - 1)
				y++;
			else if (y == m - 1)
				x++;
			else {
				if (fabs(c[x] - d[y + 1]) < fabs(c[x + 1] - d[y]))
					y++;
				else
					x++;
			}
		}
		printf("Case #%d: %.2f\n", t, len);
	}
	return 0;
}




内容概要:本文详细介绍了基于Matlab实现的“梯级水光互补系统最大化可消纳电量期望短期优化调度模型”,属于电力系统领域高水平科研成果的复现(EI级别)。该模型聚焦于梯级水电站与光伏发电系统的协同优化调度,通过构建短期优化调度框架,旨在提升可再生能源的电量消纳能力并最大化系统综合效益。研究采用先进的数学优化方法对水光资源进行联合调度,充分考虑了光伏出力的不确定性、水资源约束、系统运行边界条件及电力平衡要求,实现了在多重约束下的电量期望最大化目标。模型不仅具备严谨的理论基础,还具有良好的工程应用前景,适用于新能源高比例渗透背景下电力系统的优化调度研究与实践。; 适合人群:具备电力系统分析、可再生能源利用或优化建模背景的研究生、科研人员及工程技术人员,特别适合致力于复现高水平学术论文(EI/顶刊)研究成果的学习者与开发者。; 使用场景及目标:① 学习并掌握梯级水电与光伏系统协同调度的建模思路与关键技术;② 熟悉基于Matlab的混合整数线性规划(MILP)或其他非线性优化方法在能源系统中的实际应用;③ 提升在新能源消纳、短期调度优化等方向的科研建模能力与代码实现水平,支持二次开发与创新研究。; 阅读建议:建议结合Matlab代码与优化理论同步研读,重点理解目标函数的设计逻辑、各类物理与运行约束的数学表达以及求解器的调用流程,推荐使用YALMIP等建模工具辅助实现,以提高模型构建效率与可读性,便于深入理解与后续拓展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值