array array array (最长上升子序列变形)

本文介绍了一个有趣的编程问题:判断一个数列是否为“魔法数列”。通过移除k个元素后,若剩余数列呈非递增或非递减排列,则该数列为魔法数列。文章提供了使用最长上升子序列和最长下降子序列来解决此问题的方法。
Problem Description
One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path to escape from the museum. But Kiddo didn't want to give it back. So, Kiddo asked Conan a question. If Conan could give a right answer, Kiddo would return the ring to the museum.
Kiddo: "I have an array A and a number k, if you can choose exactly k elements from A and erase them, then the remaining array is in non-increasing order or non-decreasing order, we say A is a magic array. Now I want you to tell me whether A is a magic array. " Conan: "emmmmm..." Now, Conan seems to be in trouble, can you help him?
 

Input
The first line contains an integer T indicating the total number of test cases. Each test case starts with two integers n and k in one line, then one line with n integers: A1,A2An.
1T20
1n105
0kn
1Ai105
 

Output
For each test case, please output "A is a magic array." if it is a magic array. Otherwise, output "A is not a magic array." (without quotes).
 

Sample Input
3 4 1 1 4 3 7 5 2 4 1 3 1 2 6 1 1 4 3 5 4 6
 

Sample Output
A is a magic array. A is a magic array. A is not a magic array.
题意:给出一个数列,如果去掉k个数字,剩下的数列是非递增或者是非递减的(刚开始理解错误了递减和等差,可怕),则是魔法数列,否则不是 思路:求出最长上升子序列,最长下降子序列,与n-k比较
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int MA=100009;
int dp[MA],n;
int bin(int len,int k)
{
    int l = 1, r = len;
    while(l <= r)
    {
        int mid = (l+r)/2;
        if(k > dp[mid])
            l = mid+1;
        else
            r = mid-1;
    }
    return l;
}

int LIS(int a[])
{
    int i,j,ans=1;
    dp[1] = a[1];
    for(i = 2; i <= n; i++)
    {
        if(a[i] < dp[1])//如果比最小的还小
            j = 1;
        else if(a[i] >= dp[ans])//如果比最大的还大
            j = ++ans;
        else
            j = bin(ans,a[i]);
        dp[j] = a[i];
    }
    return ans;
}
int main()
{
    int t,k;
    int a[MA],b[MA];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&k);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            b[i]=-a[i]+100005;
        }
        int m1,m2;
        memset(dp,0,sizeof(dp));
        m1=LIS(a);
        memset(dp,0,sizeof(dp));
        m2=LIS(b);
        if(m1>=n-k||m2>=n-k) printf("A is a magic array.\n");
        else printf("A is not a magic array.\n");
    }
    return 0;
}


内容概要:本文围绕可变桨叶四旋翼无人机的规范控制与点对点运动模拟展开,重点研究优化推力分配策略在翻转动作中的应用与性能比较。通过Matlab代码实现,构建了四旋翼动力学模型,并设计了多种控制算法以实现精确的姿态调整与轨迹跟踪。研究对比了不同推力分配方案在执行高机动性翻转动作时的稳定性、能耗效率与响应速度,旨在提升无人机在复杂飞行任务中的动态性能与控制精度。该仿真研究为无人机飞控系统的设计与优化提供了理论依据和技术支持。; 适合人群:具备一定自动控制理论基础和Matlab编程能力,从事无人机控制、飞行器动力学或机器人系统研究的科研人员及研究生。; 使用场景及目标:① 实现四旋翼无人机在三维空间中的精确点对点运动控制;② 对比分析不同推力分配策略在执行翻转等高难度动作时的控制效果与能耗表现,优化飞行性能;③ 为无人机自主飞行、特技飞行及复杂环境下的机动控制提供算法验证平台。; 阅读建议:此资源以Matlab仿真为核心,建议读者结合相关控制理论知识,深入理解代码实现细节,重点关注动力学建模、控制律设计与推力分配模块。在学习过程中,应动手调试参数,复现文中翻转动作的仿真结果,并尝试拓展至其他复杂飞行任务,以加深对无人机控制机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值