Searchlights (CodeForces - 1408D)

解决一组强盗如何避开探照灯的问题,通过计算每个强盗避开每个探照灯所需的最小移动步数,并找到整体最小步数。

Searchlights

题目

There are nn robbers at coordinates (a1,b1),(a2,b2), …,(an,bn) and mm searchlight at coordinates (c1,d1), (c2,d2), …, (cm,dm).

In one move you can move each robber to the right (increase ai of each robber by one) or move each robber up (increase bi of each robber by one). Note that you should either increase all ai or all bi, you can’t increase ai for some points and bi for some other points.

Searchlight j can see a robber ii if ai≤cj and bi≤dj.

A configuration of robbers is safe if no searchlight can see a robber (i.e. if there is no pair i,j such that searchlight j can see a robber i).

What is the minimum number of moves you need to perform to reach a safe configuration?

题意

给出n个强盗坐标 ( a i , b i ),m个探照灯坐标 ( c j , d j ),每一次可以将所有 a i + 1 或者 b i + 1 ,对于 1 ≤ i ≤ n , 1 ≤ j ≤ m,均满足 a i ≤ c j & & b i ≤ d j,问最少需要操作几次

思路

(听说有O(n)的解法 但是我不会orz)
对于任意一组强盗x和探照灯y,如果x能被看到,那么可以记录下来该强盗向右走多少步能走出探照灯和向上走多少步能走出探照灯,记录完毕后将其按照向右走的步数从小到大排序。如果向右走i步可以出去,那么该项前面的海盗也都走出去了,该项后面的海盗则只能从上面走出去,另开一个mx数组记录从上面走出去的步数 然后on遍历求最值

Code

#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 1000000007
#define PI 3.1415926535898
#define INF 1000055
#define MAXN 2050
const double EPS = 1e-8;
long long read()
{
	LL x = 0, w = 1;
	char ch = 0;
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
		{
			w = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return w * x;
}
int n, m,cnt,ans=0x3f3f3f3f, mx[4000005];
struct node
{
	int x, y;
}a[4000005];
node xx[MAXN], yy[MAXN];
bool cmp(node xxx, node yyy)
{
	return xxx.x < yyy.x;
}
int main()
{
	n = read();
	m = read();
	for (register int i = 1; i <= n; i++)
	{
		xx[i].x = read();
		xx[i].y = read();
	}
	for (register int i = 1; i <= m; i++)
	{
		yy[i].x = read();
		yy[i].y = read();
		for (register int j = 1; j <= n; j++)
		{
			if (xx[j].x <= yy[i].x && xx[j].y <= yy[i].y)
			{
				a[++cnt].x = abs(xx[j].x - yy[i].x)+1;
				a[cnt].y = abs(xx[j].y - yy[i].y)+1;
			}
		}
	}
	sort(a + 1, a + cnt + 1, cmp);
	for (register int i = cnt; i >= 0; i--)
	{
		if (i == cnt)
		{
			mx[i] = a[i].y;
		}
		else
		{
			mx[i] = max(mx[i + 1], a[i].y);
		}
	}
//	mx[0] = mx[1];
	for (register int i = 0; i <= cnt; i++)
	{
		ans = min(a[i].x + mx[i+1], ans);//注意这里是mx+1
	}
	cout << ans << endl;
	return 0;
}
内容概要:本文介绍了基于贝叶斯优化的CNN-LSTM混合神经网络在时间序列预测中的应用,并提供了完整的Matlab代码实现。该模型结合了卷积神经网络(CNN)在特征提取方面的优势与长短期记忆网络(LSTM)在处理时序依赖问题上的强大能力,形成一种高效的混合预测架构。通过贝叶斯优化算法自动调参,提升了模型的预测精度与泛化能力,适用于风电、光伏、负荷、交通流等多种复杂非线性系统的预测任务。文中还展示了模型训练流程、参数优化机制及实际预测效果分析,突出其在科研与工程应用中的实用性。; 适合人群:具备一定机器学习基基于贝叶斯优化CNN-LSTM混合神经网络预测(Matlab代码实现)础和Matlab编程经验的高校研究生、科研人员及从事预测建模的工程技术人员,尤其适合关注深度学习与智能优化算法结合应用的研究者。; 使用场景及目标:①解决各类时间序列预测问题,如能源出力预测、电力负荷预测、环境数据预测等;②学习如何将CNN-LSTM模型与贝叶斯优化相结合,提升模型性能;③掌握Matlab环境下深度学习模型搭建与超参数自动优化的技术路线。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注贝叶斯优化模块与混合神经网络结构的设计逻辑,通过调整数据集和参数加深对模型工作机制的理解,同时可将其框架迁移至其他预测场景中验证效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值