组合之01转换法

本文详细介绍了如何在数组中找到特定组合并进行转换,同时将所有匹配元素移动到数组左侧的过程。通过提供的代码示例,演示了如何实现这一操作。

m个数中取n个数的所有组合问题

从左到右扫描数组元素值的“10”组合,找到第一个“10”组合后将其变为“01”组合,同时将其左边的所有“1”全部移动到数组的最左端

代码如下:

#include <iostream>

using namespace std;

#define SIZE 100

struct data{
	int elem;
	int b;
};

inline void move(data tmp[], int num, int r){
	for(int i = 0; i < num; i++){
		tmp[i].b = 1;
	}
	for(int j = num; j < r; j++){
		tmp[j].b = 0;
	}
}

inline void println(data tmp[], int len){
	for(int i = 0; i < len; i++){
		if(tmp[i].b == 1)
			cout << tmp[i].elem << " ";
	}
	cout << endl;
}

void comb(int arr[], int len, int count){
	data tmp[SIZE];

	for(int i = 0; i < len; i++){
		tmp[i].elem = arr[i];
		if(i < count){
			tmp[i].b = 1;
		}
		else{
			tmp[i].b = 0;
		}
	}
	println(tmp, len);

	while(true){
		int j = 0;
		int num = 0;
		while(j+1 < len){
			if(tmp[j].b == 1){
				num++;
				if(tmp[j+1].b == 0){
					tmp[j].b = 0;
					tmp[j+1].b = 1;
					move(tmp, num-1, j);
					break;
				}
			}
			++j;	
		}
		if(j+1 < len)
			println(tmp, len);
		else
			break;
	}
}

int main(int argc, char* argv[])
{
	int testArr[] = {2, 5, 1, 7, 4};
	int len  = sizeof(testArr)/sizeof(int);

	comb(testArr, len, 3);

	return 0;
}


 

### 组合导航系统中的坐标系转换 #### 地理坐标系与惯性坐标系间的转换 在组合导航系统中,不同坐标系之间的转换至关重要。对于从地心地固坐标系(e系)到当地水平地理坐标系(g(n)系),即东北天(ENU)坐标系的转换可以通过特定矩阵完成[^1]: \[ C_{eg} = \begin{bmatrix} -\sin(L)\cos(\lambda) & -\sin(L)\sin(\lambda) & \cos(L) \\ -\sin(\lambda) & \cos(\lambda) & 0 \\ -\cos(L)\cos(\lambda)& -\cos(L)\sin(\lambda)& -\sin(L) \end{bmatrix} \] 其中 \(L\) 和 \(\lambda\) 分别代表纬度和经度。 为了实现从 g(n) 系到 b(body,载体)系的转换,当已知姿态角 roll (横滚), pitch (俯仰), yaw (偏航)时,可以构建相应的方向余弦矩阵(DCM)[^5]: ```matlab function DCM = getDCM(roll, pitch, yaw) % 定义旋转角度对应的弧度值 phi = deg2rad(roll); theta = deg2rad(pitch); psi = deg2rad(yaw); % 构建方向余弦矩阵 cphi = cos(phi); sphi = sin(phi); ctheta= cos(theta); stheta= sin(theta); cpsi = cos(psi); spsi = sin(psi); DCM = [ cpsi*ctheta cpsi*stheta*sphi-spsi*cphi cpsi*stheta*cphi+spsi*sphi; spsi*ctheta spsi*stheta*sphi+cpsi*cphi spsi*stheta*cphi-cpsi*sphi; -stheta ctheta*sphi ctheta*cphi]; end ``` 此函数接收三个参数——roll、pitch 和 yaw 的角度,并返回一个表示两个坐标系之间相对定向的方向余弦矩阵。 #### INS/GNSS联合使用的坐标变换需求 考虑到INS系统的特性,在实际应用中往往需要将其输出的数据由载体坐标系转换至其他更易于理解和处理的形式,比如地固坐标系或WGS-84这样的全球标准坐标体系。这不仅有助于提高定位精度,还便于与其他传感器数据融合使用[^3]。 #### 迭代法用于空间直角坐标到大地坐标的转换 针对某些复杂的坐标转换场景,如将空间直角坐标(X,Y,Z)转化为大地坐标(B,L,H),则可能需要用到迭代算法来逐步逼近真实值。这类方法基于初始猜测并通过不断调整直至满足收敛条件获得最终结果[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值