Gym - 101102F F. Exchange

字典序最小字符串算法
本文介绍了一种算法,该算法通过交换字符串中两个不同字符的位置来生成字典序最小的字符串。具体实现包括读取输入字符串、统计字符频率及执行字符交换操作,最终输出经过零次或一次字符交换后的最小字典序字符串。

Given a string of lowercase English letters. You are allowed to choose two letters that exist in any position in the string, replace all occurrences of the first letter you chose with the second one, and replace all occurrences of the second letter you chose with the first one.

Your task is to find the string that comes first in dictionary order among all possible strings that you can get by performing the above operation at most once.

For example, by exchanging letter ‘a’ with letter ‘h’ in string “hamza”, we can get string “ahmzh”.

Input

The first line of input contains a single integer T, the number of test cases.

Each test case contains a non-empty string on a single line that contains no more than 105 lowercase English letters.

Output

For each test case, print the required string on a single line.

Example

题意:可以对字符串进行一个操作,把2个字母互换(这2个字母是不同的),一旦互换必须把所有x换成y,所有y换成x,最多可以进行一次这样的操作,求字典序最小的字符串。

Input

3
hamza
racecar
mca

Output

ahmzh
arcecra
acm
#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
#include<math.h>
using namespace std;
char s[100050];
int main()
{
    int t,i;
    cin>>t;
    while(t--)
    {
        scanf("%s",s);
        int len=strlen(s);
        int c[26];
        memset(c,0,sizeof(c));
        for(i=0; i<len; i++)
        {
            c[s[i]-'a']++;
        }
        char a,b;
        int k=0,j;
        for(i=0; i<26; i++)
        {
            if(c[i])
            {
                a='a'+i;
                if(a<s[k])
                {
                    b=s[k];
                    break;
                }
                else if(a==s[k])
                {
                    j=k;
                    while(s[j]>=s[k])
                        k++;
                }
            }
        }
        if(i==26)
        {
            printf("%s\n",s);
            continue;
        }
        for(i=0; i<len; i++)
        {
            if(s[i]==a)
            s[i]=b;
            else if(s[i]==b)
            s[i]=a;
        }
        printf("%s\n",s);
    }
    return 0;
}

 

在Isaac Sim中完整模拟宇树机器人G1的详细过程 1. 环境准备 安装NVIDIA Omniverse Launcher并启动Isaac Sim 2023.1+版本1 确保系统满足: NVIDIA RTX 3070+ GPU 32GB+ RAM Ubuntu 20.04/Windows 11 安装依赖: Bash pip install omni.isaac.core omni.isaac.motion_generation 2. 获取机器人模型 官方资源: 从Unitree GitHub下载G1 URDF模型 或使用Isaac Sim内置资源库:Assets > Robots > Quadrupeds 模型转换(如需): Python from omni.isaac.core.utils.extensions import enable_extension enable_extension("omni.isaac.urdf_importer") 3. 导入并配置机器人 Python from omni.isaac.core import World from omni.isaac.core.robots import Robot # 创建世界 world = World(stage_units_in_meters=1.0) # 导入机器人 g1_robot = world.scene.add( Robot( prim_path="/World/G1", name="G1_Robot", usd_path="/path/to/unitree_g1.usd", # 替换为实际路径 position=np.array([0, 0, 0.5]) ) ) world.reset() 4. 物理参数配置 Python # 设置关节驱动器(PID控制) from omni.isaac.core.utils.types import ArticulationAction joint_properties = { "hip_joint": {"stiffness": 800, "damping": 40}, "thigh_joint": {"stiffness": 500, "damping": 30}, "calf_joint": {"stiffness": 400, "damping": 20} } for joint_name, params in joint_properties.items(): g1_robot.set_joint_properties( joint_name, stiffness=params["stiffness"], damping=params["damping"] ) 5. 运动控制实现 Python # 步态控制器示例 def trot_gait(phase): # 生成步态模式 (相位控制) leg_phases = [phase, (phase + 0.5) % 1, (phase + 0.5) % 1, phase] joint_targets = [] for i, phase_val in enumerate(leg_phases): # 计算关节角度 (简化模型) hip_angle = 0.2 * np.sin(2*np.pi*phase_val) thigh_angle = -0.8 + 0.4 * np.sin(2*np.pi*phase_val) calf_angle = 1.2 - 0.6 * np.sin(2*np.pi*phase_val) joint_targets.extend([hip_angle, thigh_angle, calf_angle]) return joint_targets # 主仿真循环 phase = 0.0 for i in range(1000): world.step(render=True) phase = (phase + 0.01) % 1.0 targets = trot_gait(phase) g1_robot.apply_action(ArticulationAction(joint_positions=targets)) 6. 传感器集成 Python # 添加深度相机 from omni.isaac.sensor import Camera camera = Camera( prim_path="/World/G1/head_camera", resolution=(1024, 768), frequency=30, position=np.array([0.3, 0, 0.1]) ) # 获取数据 rgb_data = camera.get_rgba() depth_data = camera.get_depth() 7. 仿真环境构建 地形生成: Python from omni.isaac.terrain_utils import create_rough_ground_plane create_rough_ground_plane("/World/terrain", scale=(10,10,1)) 障碍物添加: Python from omni.isaac.core.objects import DynamicCuboid obstacles = [] for i in range(5): obstacle = world.scene.add(DynamicCuboid( name=f"obs_{i}", position=np.array([i*0.5, 0, 0.2]), size=0.3 )) 8. 高级功能 ROS2集成: Python # 在extension_manager中启用ROS2 bridge from omni.isaac.core.utils.extensions import enable_extension enable_extension("omni.isaac.ros2_bridge") # 创建ROS2节点 import rclpy from rclpy.node import Node class G1Controller(Node): def __init__(self): super().__init__('g1_controller') self.subscription = self.create_subscription( Twist, 'cmd_vel', self.listener_callback, 10) 强化学习训练: Python from omni.isaac.gym.vec_env import VecEnvBase env = VecEnvBase(headless=False) task = G1LocomotionTask(name="G1_RL") env.set_task(task, backend="torch") # 创建PPO训练器 from rl_games.common import env_configurations from rl_games.algos_torch import players trainer = ppo.PPOAgent() trainer.train() 常见问题解决 模型抖动问题: 调整物理子步长:world.set_simulation_dt(physics_dt=1/120, rendering_dt=1/60) 增加接触偏移:g1_robot.set_collision_properties(contact_offset=0.1) 运动不稳定: 优化PID参数 添加关节摩擦力补偿: Python g1_robot.set_joint_friction_coefficients(values=[0.1]*12) 性能优化: 启用USD实例化:g1_robot.enable_instancing(True) 使用低精度模式:world.set_render_resolution(1280, 720) 仿真效果验证 运动学测试: Python # 验证关节运动范围 for joint_idx in range(12): print(f"Joint {joint_idx} limits: {g1_robot.get_joint_limits(joint_idx)}") 动力学验证: Python # 检查质心位置 com = g1_robot.get_center_of_mass() print(f"CoM position: {com}") 总结300字用123排列纯文字
最新发布
08-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值