hihocoder #1228 : Mission Impossible 6 模拟

文本编辑器模拟实现
本文介绍了一个简单的文本编辑器模拟程序的设计与实现过程。该程序使用C++编写,支持基本的编辑操作如插入、删除、复制及粘贴等,并考虑了光标位置和覆盖模式的影响。通过对每种操作的逐一解析,展示了如何处理这些命令来更新内部数据结构。

总结 :1 .题意理解
2. 插入要从后往前枚举更新, 删除要从前往后枚举更新数据结构没学好。。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 100005
using namespace std;
int flagOve;
int po, copyPoStart, copyPoEnd;
char ans[maxn];
int l, m;
char update[maxn];
char cop[maxn];
int copLen;
void copyEnd()//OK
{
     int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd);
     copLen = 0;
     for(int i = L; i < R; i++) cop[copLen++] = ans[i];
     copyPoStart = -1;
}
void L()//OK
{
     if(copyPoEnd > 0) copyPoEnd--;
     if(po > 0) po--;
}
void R()//Ok
{
     if(copyPoEnd < l) copyPoEnd++;
     if(po < l) po++;
}
void S()//OK
{
    copyPoStart = -1;
    flagOve ^= 1;
}
void D()//OK
{
     if(copyPoStart != -1)
     {
        int L = min(copyPoStart, copyPoEnd), R = max(copyPoStart, copyPoEnd);
        for(int i = R, j = L; i < l; i++, j++) ans[j] = ans[i];
        l -= (R - L);
        po = L;
     }
     else{
          for(int i = po; i < l - 1; i++) ans[i] = ans[i + 1];
          if(po != l) l--;
     }
    copyPoStart = -1;
}
void B()//OK
{
    copyPoStart = -1;
    int pre = po - 1;
    if(pre == -1)return ;
    else
    {
        for(int i = pre; i < l - 1; i++) ans[i] = ans[i + 1];
        po--;
        l--;
    }
}
void C() //OK
{
    if(copyPoStart != -1) copyEnd();
    else
    {
       copyPoStart = po;
       copyPoEnd = po;
    }
}
void V()//OK
{
     copyPoStart = -1;
     if(flagOve)
     {
        if(copLen + po <= m)
        {
            for(int i = po; i < copLen + po; i++) ans[i] = cop[i - po];
            l = max(l, copLen + po);
            po += copLen;
        }
     }
     else
     {
        if(copLen + l <= m)
        {
            for(int i = l, j = copLen + l; i >= po; i--, j--) ans[j] = ans[i];
            //for(int i = po, j = copLen + po; i < l; i++, j++) ans[j] = ans[i];
            for(int i = po; i < po + copLen; i++) ans[i] = cop[i - po];
            l += copLen;
            po += copLen;
        }
     }
}
void low(char ss)
{
     copyPoStart = -1;
     if(flagOve) {
          if(po != l){ ans[po] = ss; po++; }
          else if(l != m)
          {
              ans[po] = ss;
              po++;
              l++;
          }
      }
     else
     {
      if(l == m)return;
      for(int i = l; i > po; i--) ans[i] = ans[i - 1];
      ans[po] = ss;
      l++;
      po++;
     }
}
void init()
{
     copyPoStart = -1;
     po = 0;
     l = 0;
     copLen = 0;
     flagOve = 0;
}
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
       scanf("%d %s", &m, update);
       init();
       for(int i = 0; update[i]; i++)
       {
           if(update[i] >= 'a' && update[i] <= 'z') low(update[i]);
           else if(update[i] == 'L') L();
           else if(update[i] == 'R') R();
           else if(update[i] == 'S') S();
           else if(update[i] == 'D') D();
           else if(update[i] == 'B') B();
           else if(update[i] == 'C') C();
           else if(update[i] == 'V') V();
       }
       if(l == 0) printf("NOTHING\n");
       else
       {
         for(int i = 0; i < l; i++)printf("%c", ans[i]);
         printf("\n");
       }
    }
    return 0;
}
【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器模拟器的研究展开,重点介绍基于Matlab代码实现的四轴飞行器动力学建模与仿真方法。研究构建了考虑非线性特性的飞行器数学模型,涵盖姿态动力学与运动学方程,实现了三自由度(滚转、俯仰、偏航)的精确模拟。文中详细阐述了系统建模过程、控制算法设计思路及仿真结果分析,帮助读者深入理解四轴飞行器的飞行动力学特性与控制机制;同时,该模拟器可用于算法验证、控制器设计与教学实验。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及无人机相关领域的工程技术人员,尤其适合从事飞行器建模、控制算法开发的研究生和初级研究人员。; 使用场景及目标:①用于四轴飞行器非线性动力学特性的学习与仿真验证;②作为控制器(如PID、LQR、MPC等)设计与测试的仿真平台;③支持无人机控制系统教学与科研项目开发,提升对姿态控制与系统仿真的理解。; 阅读建议:建议读者结合Matlab代码逐模块分析,重点关注动力学方程的推导与实现方式,动手运行并调试仿真程序,以加深对飞行器姿态控制过程的理解。同时可扩展为六自由度模型或加入外部干扰以增强仿真真实性。
基于分布式模型预测控制DMPC的多智能体点对点过渡轨迹生成研究(Matlab代码实现)内容概要:本文围绕“基于分布式模型预测控制(DMPC)的多智能体点对点过渡轨迹生成研究”展开,重点介绍如何利用DMPC方法实现多智能体系统在复杂环境下的协同轨迹规划与控制。文中结合Matlab代码实现,详细阐述了DMPC的基本原理、数学建模过程以及在多智能体系统中的具体应用,涵盖点对点转移、避障处理、状态约束与通信拓扑等关键技术环节。研究强调算法的分布式特性,提升系统的可扩展性与鲁棒性,适用于多无人机、无人车编队等场景。同时,文档列举了大量相关科研方向与代码资源,展示了DMPC在路径规划、协同控制、电力系统、信号处理等多领域的广泛应用。; 适合人群:具备一定自动化、控制理论或机器人学基础的研究生、科研人员及从事智能系统开发的工程技术人员;熟悉Matlab/Simulink仿真环境,对多智能体协同控制、优化算法有一定兴趣或研究需求的人员。; 使用场景及目标:①用于多智能体系统的轨迹生成与协同控制研究,如无人机集群、无人驾驶车队等;②作为DMPC算法学习与仿真实践的参考资料,帮助理解分布式优化与模型预测控制的结合机制;③支撑科研论文复现、毕业设计或项目开发中的算法验证与性能对比。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注DMPC的优化建模、约束处理与信息交互机制;按文档结构逐步学习,同时参考文中提及的路径规划、协同控制等相关案例,加深对分布式控制系统的整体理解。
compiling main.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Inc/path_planner.h(10): error: #256: invalid redeclaration of type name "Cylinder" (declared at line 11 of "../Core/Inc/motion.h") } Cylinder; ../Core/Inc/path_planner.h(13): error: #101: "TASK_SIMPLE_EXIT" has already been declared in the current scope TASK_SIMPLE_EXIT, ../Core/Inc/path_planner.h(14): error: #101: "TASK_SNAKE_PATH" has already been declared in the current scope TASK_SNAKE_PATH, ../Core/Inc/path_planner.h(15): error: #101: "TASK_CIRCLE_TWO_COLORS" has already been declared in the current scope TASK_CIRCLE_TWO_COLORS, ../Core/Inc/path_planner.h(16): error: #101: "TASK_COLUMN_SWAP" has already been declared in the current scope TASK_COLUMN_SWAP, ../Core/Inc/path_planner.h(17): error: #101: "TASK_RANDOM_DETECT" has already been declared in the current scope TASK_RANDOM_DETECT, ../Core/Inc/path_planner.h(18): error: #101: "TASK_DETECT_AND_PATH" has already been declared in the current scope TASK_DETECT_AND_PATH, ../Core/Inc/path_planner.h(19): error: #101: "TASK_NONE" has already been declared in the current scope TASK_NONE ../Core/Inc/path_planner.h(20): error: #256: invalid redeclaration of type name "TaskMode" (declared at line 21 of "../Core/Inc/motion.h") } TaskMode; ../Core/Src/main.c(42): error: #147: declaration is incompatible with "Cylinder cylinders[10]" (declared at line 23 of "../Core/Inc/motion.h") Cylinder cylinders[ AX_CYLINDERS]; ../Core/Src/main.c(112): error: #20: identifier "rx_byte" is undefined if (rx_byte == &#39;\n&#39; || openmv_index >= sizeof(openmv_buffer) - 1) { ../Core/Src/main.c(112): error: #20: identifier "openmv_index" is undefined if (rx_byte == &#39;\n&#39; || openmv_index >= sizeof(openmv_buffer) - 1) { ../Core/Src/main.c(112): error: #20: identifier "openmv_buffer" is undefined if (rx_byte == &#39;\n&#39; || openmv_index >= sizeof(openmv_buffer) - 1) { ../Core/Src/main.c(115): error: #20: identifier "openmv_data_ready" is undefined openmv_data_ready = 1; ../Core/Src/main.c(119): error: #20: identifier "rx_byte" is undefined HAL_UART_Receive_IT(&huart1, &rx_byte, 1); ../Core/Src/main.c(124): error: #20: identifier "mission_running" is undefined mission_running = 1; ../Core/Src/main.c(125): error: #20: identifier "start_time" is undefined start_time = HAL_GetTick(); ../Core/Src/main.c(126): error: #20: identifier "current_state" is undefined current_state = TASK_DETECTING; ../Core/Src/main.c(126): error: #20: identifier "TASK_DETECTING" is undefined current_state = TASK_DETECTING; ../Core/Src/main.c(131): error: #20: identifier "start_time" is undefined return (HAL_GetTick() - start_time) > timeout; ../Core/Src/main.c(131): error: #20: identifier "timeout" is undefined return (HAL_GetTick() - start_time) > timeout; ../Core/Src/main.c(156): error: #20: identifier "openmv_buffer" is undefined char *token = strtok(openmv_buffer, ";"); ../Core/Src/main.c(210): error: #20: identifier "current_state" is undefined current_state = TASK_COMPLETED; ../Core/Src/main.c(210): error: #20: identifier "TASK_COMPLETED" is undefined current_state = TASK_COMPLETED; ../Core/Src/main.c(215): error: #20: identifier "current_state" is undefined switch (current_state) { ../Core/Src/main.c(216): error: #20: identifier "TASK_IDLE" is undefined case TASK_IDLE: ../Core/Src/main.c(217): error: #20: identifier "mission_running" is undefined if (mission_running) { ../Core/Src/main.c(218): error: #20: identifier "TASK_DETECTING" is undefined current_state = TASK_DETECTING; ../Core/Src/main.c(222): error: #20: identifier "TASK_DETECTING" is undefined case TASK_DETECTING: ../Core/Src/main.c(223): error: #20: identifier "openmv_data_ready" is undefined if (openmv_data_ready) { ../Core/Src/main.c: 1 warning, 30 errors compiling pid.c... ../Core/Inc/motion.h(25): error: #20: identifier "PID_Controller" is undefined extern PID_Controller angle_pid; ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\pid.c: 1 warning, 1 error compiling tim.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/tim.c: 1 warning, 0 errors compiling usart.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/usart.c: 1 warning, 0 errors compiling i2c.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/i2c.c: 1 warning, 0 errors compiling gpio.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/gpio.c: 1 warning, 0 errors compiling encoder.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\encoder.c: 1 warning, 0 errors compiling kalman_filter.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\kalman_filter.c: 1 warning, 0 errors compiling jy61p.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\jy61p.c: 1 warning, 0 errors compiling motor.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\motor.c: 1 warning, 0 errors compiling ultrasonic.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\ultrasonic.c: 1 warning, 0 errors compiling stm32f1xx_hal_msp.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/stm32f1xx_hal_msp.c: 1 warning, 0 errors compiling stm32f1xx_it.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Src/stm32f1xx_it.c: 1 warning, 0 errors compiling path_planner.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Inc/path_planner.h(10): error: #256: invalid redeclaration of type name "Cylinder" (declared at line 11 of "../Core/Inc/motion.h") } Cylinder; ../Core/Inc/path_planner.h(13): error: #101: "TASK_SIMPLE_EXIT" has already been declared in the current scope TASK_SIMPLE_EXIT, ../Core/Inc/path_planner.h(14): error: #101: "TASK_SNAKE_PATH" has already been declared in the current scope TASK_SNAKE_PATH, ../Core/Inc/path_planner.h(15): error: #101: "TASK_CIRCLE_TWO_COLORS" has already been declared in the current scope TASK_CIRCLE_TWO_COLORS, ../Core/Inc/path_planner.h(16): error: #101: "TASK_COLUMN_SWAP" has already been declared in the current scope TASK_COLUMN_SWAP, ../Core/Inc/path_planner.h(17): error: #101: "TASK_RANDOM_DETECT" has already been declared in the current scope TASK_RANDOM_DETECT, ../Core/Inc/path_planner.h(18): error: #101: "TASK_DETECT_AND_PATH" has already been declared in the current scope TASK_DETECT_AND_PATH, ../Core/Inc/path_planner.h(19): error: #101: "TASK_NONE" has already been declared in the current scope TASK_NONE ../Core/Inc/path_planner.h(20): error: #256: invalid redeclaration of type name "TaskMode" (declared at line 21 of "../Core/Inc/motion.h") } TaskMode; ..\Core\Src\path_planner.c: 1 warning, 9 errors compiling motion.c... ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ../Core/Inc/motion.h(39): warning: #1-D: last line of file ends without a newline #endif /* __MOTION_H */ ..\Core\Src\motion.c: 2 warnings, 0 errors "carL\carL.axf" - 40 Error(s), 16 Warning(s).
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值