习题7-11(uva-12569)

本文介绍了一种基于广度优先搜索(BFS)的迷宫机器人路径规划算法。该算法利用多种数据结构如列表、栈等来实现机器人在迷宫中寻找从起点到终点的最短路径。通过不断探索相邻节点并更新状态,最终输出最优路径。
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 15,maxm = 1e6;
struct Node {
	Node() :robot(0), stone(0) {}
	Node(int a, int b) :robot(a), stone(b) {}
	int robot;//机器人位置
	int stone;//移动物标记
}node[maxm], res[maxm];

int vis[1 << maxn][maxn],n,m,s,t,before[maxm],cnt[maxm];
vector<int> g[maxn];


void printAns(int cur) {
	if (cur == 0) return;
	printAns(before[cur]);
	cout << res[cur].robot << " " << res[cur].stone << endl;
}

void bfs()
{
	int head = 0, tail = 1,over = (t - 1);

	memset(vis, 0, sizeof(vis));
	vis[node[0].stone][node[0].robot] = 1;

	before[0] = -1;
	cnt[0] = 0;

	Node cur;
	while (head < tail) {
		cur = node[head];
		if (cur.robot == over) {
			cout << cnt[head] << endl;
			printAns(head);
			return;
		}
		for (int i = 0; i < n; i++) {
			//检测当前二进制位是否有可以移动的对象
			if (!((1 << i) & cur.stone)) continue;
			for (int j = 0; j < g[i].size(); j++) {
				int a = g[i][j];
				//移动的位置是否是空位
				if(((1 << a) & cur.stone)) continue;
				//尝试添加到末尾
				Node& next = node[tail];
				next = cur;
				//如果是移动机器人 
				if (next.robot == i) next.robot = a;
				//更新 从 i 移动到 a
				next.stone = (next.stone & ~(1 << i)) | (1 << a);
				//是否访问过
				if(vis[next.stone][next.robot]) continue;

				vis[next.stone][next.robot] = 1;

				//记录前驱
				before[tail] = head;
				//记录行动轨迹
				res[tail] = Node(i+1, a+1);
				//记录长度
				cnt[tail] = cnt[head] + 1;

				++tail;
			}
		}
		++head;
	}
}
int main()
{
	int cnt, kcase = 0,temp,a,b;
	cin >> cnt;
	while (cnt--)
	{
		cin >> n >> m >> s >> t;
		//记录机器人位置
		node[0].robot =  (s - 1);
		//机器人和障碍物都是可以移动的
		node[0].stone = 1 << (s - 1);

		for (int i = 0; i < m; i++) {
			//添加障碍物
			cin >> temp;
			node[0].stone |= 1 << (temp - 1);
		}
		for (int i = 0; i < maxn; i++) g[i].clear();

		for (int i = 1; i < n; i++) {
			cin >> a >> b;
			g[a-1].push_back(b-1);
			g[b-1].push_back(a-1);
		}

		cout << "Case " << ++kcase << ": ";
		bfs();
	}
	return 0;
}
MATLAB主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性内容概要:本文主要介绍了一种在MATLAB环境下实现的主动噪声和振动控制算法,该算法针对较大的次级路径变化具有较强的鲁棒性。文中详细阐述了算法的设计原理与实现方法,重点解决了传统控制系统中因次级路径动态变化导致性能下降的问题。通过引入自适应机制和鲁棒控制策略,提升了系统在复杂环境下的稳定性和控制精度,适用于需要高精度噪声与振动抑制的实际工程场景。此外,文档还列举了多个MATLAB仿真实例及相关科研技术服务内容,涵盖信号处理、智能优化、机器学习等多个交叉领域。; 适合人群:具备一定MATLAB编程基础和控制系统理论知识的科研人员及工程技术人员,尤其适合从事噪声与振动控制、信号处理、自动化等相关领域的研究生和工程师。; 使用场景及目标:①应用于汽车、航空航天、精密仪器等对噪声和振动敏感的工业领域;②用于提升现有主动控制系统对参数变化的适应能力;③为相关科研项目提供算法验证与仿真平台支持; 阅读建议:建议读者结合提供的MATLAB代码进行仿真实验,深入理解算法在不同次级路径条件下的响应特性,并可通过调整控制参数进一步探究其鲁棒性边界。同时可参考文档中列出的相关技术案例拓展应用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值