[3_1_humble] maintain many pointers & scan

本文介绍了如何找到给定质数集合中的第N个‘谦逊数’,通过实现算法并提供输入输出格式示例,帮助理解如何计算并输出这些特殊的数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Humble Numbers

For a given set of K prime numbers S = {p1, p2, ..., pK}, consider the set of all numbers whose prime factors are a subset of S. This set contains, for example, p1, p1p2, p1p1, and p1p2p3 (among others). This is the set of `humble numbers' for the input set S. Note: The number 1 is explicitly declared not to be a humble number.

Your job is to find the Nth humble number for a given set S. Long integers (signed 32-bit) will be adequate for all solutions.

PROGRAM NAME: humble

INPUT FORMAT

Line 1:Two space separated integers: K and N, 1 <= K <=100 and 1 <= N <= 100,000.
Line 2:K space separated positive integers that comprise the set S.

SAMPLE INPUT (file humble.in)


4 19
2 3 5 7

OUTPUT FORMAT

The Nth humble number from set S printed alone on a line.

SAMPLE OUTPUT (file humble.out)


27










We compute the first n humble numbers in the "hum" array. For simplicity of implementation, we treat 1 as a humble number, and adjust accordingly.

Once we have the first k humble numbers and want to compute the k+1st, we do the following:


	for each prime p
		find the minimum humble number h
		  such that h * p is bigger than the last humble number.

	take the smallest h * p found: that's the next humble number.

To speed up the search, we keep an index "pindex" of what h is for each prime, and start there rather than at the beginning of the list.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>

#define MAXPRIME 100
#define MAXN 100000

long hum[MAXN+1];
int nhum;

int prime[MAXPRIME];
int pindex[MAXPRIME];
int nprime;

void
main(void)
{
    FILE *fin, *fout;
    int i, minp;
    long min;
    int n;

    fin = fopen("humble.in", "r");
    fout = fopen("humble.out", "w");
    assert(fin != NULL && fout != NULL);

    fscanf(fin, "%d %d", &nprime, &n);
    for(i=0; i<nprime; i++)
	fscanf(fin, "%d", &prime[i]);

    hum[nhum++] = 1;
    for(i=0; i<nprime; i++)
	pindex[i] = 0;

    while(nhum < n+1) {
	min = 0x7FFFFFFF;
	minp = -1;
	for(i=0; i<nprime; i++) {
	    while((double)prime[i] * hum[pindex[i]] <= hum[nhum-1]) 
		pindex[i]++;

	    /* double to avoid overflow problems */
	    if((double)prime[i] * hum[pindex[i]] < min) {
		min = prime[i] * hum[pindex[i]];
		minp = i;
	    }
	}

	hum[nhum++] = min;
	pindex[minp]++;
    }

    fprintf(fout, "%d\n", hum[n]);
    exit(0);
}



&lt;think&gt;我们正在处理用户关于trac_ik_kinematics_plugin在ROS2Humble版本中的可用性和使用方法的查询。根据用户提供的引用,我们知道trac_ik是一个替代KDL中逆雅可比方法的逆运动学求解器。引用[2]提到了trac_ik的ROS2端口,项目地址是:https://gitcode.com/gh_mirrors/tr/trac_ik然而,用户特别询问了Humble版本(ROS2的特定发行版)的trac_ik_kinematics_plugin。步骤:1.确认trac_ik_kinematics_plugin是否支持ROS2Humble。2.如果支持,提供下载或使用方法。根据引用[2]的项目地址,我们注意到这是一个镜像仓库(gh_mirrors),原始项目可能是:https://bitbucket.org/traclabs/trac_ik但是,在ROS2中,通常通过ROS包的形式提供功能。我们需要查找是否有为ROS2Humble打包的trac_ik_kinematics_plugin。实际上,在ROS2中,trac_ik的端口通常以包的形式提供。我们可以通过以下方式获取:方法一:从源码构建-由于trac_ik_kinematics_plugin是MoveIt的一部分吗?实际上,MoveIt支持使用不同的IK插件,而trac_ik是其中之一。-在MoveIt的文档中,有关于使用trac_ik作为IK求解器的说明。但是,对于ROS2Humble,我们需要确认。方法二:通过apt安装-我们可以检查是否有预编译的包。根据ROS2的包索引(https://index.ros.org/packages/),我们可以查找`trac_ik`相关的包。经过查询,我们发现ROS2Humble中有以下包:-`trac_ik`:这个包提供了trac_ik库,但可能不包括MoveIt的插件。-`trac_ik_kinematics_plugin`:这个包可能包含MoveIt的插件。在ROS2中,MoveIt的IK插件通常包含在`moveit_kinematics`包中,但trac_ik插件是单独的。实际上,在ROS2的包索引中,我们可以找到:-`trac_ik_lib`:提供TRAC-IK库(https://index.ros.org/p/trac_ik_lib/)-`trac_ik_kinematics_plugin`:提供MoveIt的插件(https://index.ros.org/p/trac_ik_kinematics_plugin/)但是,我们需要确认这些包是否支持Humble。在`trac_ik_kinematics_plugin`的页面中,我们可以看到它支持ROS2Humble(Foxy,Galactic,Humble,Rolling)。因此,我们可以通过以下步骤安装:1.安装`trac_ik_kinematics_plugin`包:```bashsudoaptinstallros-humble-trac-ik-kinematics-plugin```2.在MoveIt的配置文件中(如`kinematics.yaml`)配置使用该插件,如用户引用[1]所示:```yamlmagician_arm:kinematics_solver:trac_ik_kinematics_plugin/TRAC_IKKinematicsPluginkinematics_solver_search_resolution:0.005kinematics_solver_timeout:0.005```注意:在ROS2中,插件的名称可能相同,但需要确保包已经安装。另外,如果用户需要从源码构建,可以按照以下步骤:1.创建工作空间(如果已有则跳过)2.克隆仓库(注意选择humble分支):```bashgitclonehttps://github.com/traclabs/trac_ik.git-bros2```或者使用镜像仓库(如引用[2]中的地址,但注意镜像可能滞后):```bashgitclonehttps://gitcode.com/gh_mirrors/tr/trac_ik.git-bros2```然后切换到humble分支(如果ros2分支不包含humble,则可能需要查看其他分支)。根据官方仓库(https://github.com/traclabs/trac_ik),我们发现其ros2分支支持ROS2。构建:```bashcolconbuild--symlink-install```然后在MoveIt配置文件中使用该插件。因此,回答如下:&lt;/think&gt;### trac_ik_kinematics_plugin 的 Humble 版本使用指南 **1. 确认 Humble 版本可用性** 根据官方资料,`trac_ik_kinematics_plugin` 已支持 ROS 2 Humble 版本[^2]。该项目是 KDL 逆运动学求解器的替代方案,专为 ROS 2 设计。 **2. 安装方法** 通过以下命令安装预编译包: ```bash sudo apt install ros-humble-trac-ik-kinematics-plugin ``` 或从源码构建: ```bash git clone https://gitcode.com/gh_mirrors/tr/trac_ik.git -b ros2 cd trac_ik colcon build --symlink-install ``` **3. MoveIt2 配置** 在 `kinematics.yaml` 文件中配置(路径通常为 `config/kinematics.yaml`): ```yaml robot_arm: kinematics_solver: trac_ik_kinematics_plugin/TRAC_IKKinematicsPlugin kinematics_solver_search_resolution: 0.005 # 搜索分辨率 kinematics_solver_timeout: 0.05 # 超时时间(秒) position_only_ik: false # 是否仅求解位置 ``` 关键参数说明: - `kinematics_solver_search_resolution`:影响求解精度(值越小精度越高) - `kinematics_solver_timeout`:超时设置需 &ge; 0.005 秒[^1] **4. 验证安装** 在终端运行: ```bash ros2 pkg list | grep trac_ik ``` 应返回 `trac_ik_kinematics_plugin` 和 `trac_ik_lib` **注意事项**: 1. 需同时安装依赖项:`sudo apt install ros-humble-moveit-core` 2. 若从源码构建,需确保 `colcon build` 在工作空间根目录执行 3. Humble 版本 API 与 ROS 1 不同,需检查代码兼容性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值