Defense Lines UVA - 1471

题意:给出一序列,求删除一段连续的序列之后,求出长度最长的上升子序列。

这道题需要在NlogN以下的复杂度。

首先对数组进行预处理,我们用F[i]记录以a[i]为开头的最长子序列长度,g[i]记录以a[i]为结尾的最长子序列长度。

我们按a[i]从头到尾进行遍历,然后维护一个存有包含a[i]与g[i]结构体的集合。

在集合中寻找大小小于a[i]的数值时,二分查找。这样时间负责度便为NlogN

在维护集合时,a[i]与g[i]都要满足严格递增的,因此对于集合的维护是这样的: 如果这个数的前一个数的g>=它,那么把它放进去是不妥的。 反之就要将它放进集合,这样一来就要检查他之后的数的g是不是>它。

代码:

#include<bits/stdc++.h>
using namespace std;
struct point
{
    int a,l;
    point(int x=0,int y=0)
    {
        a=x;
        l=y;
    }
    bool operator < (const point &b)const{
    return a<b.a;
    }
};
int a[200010],f[200010],g[200010];//f[i]以a[i]开头的递增子序列,g[i]以a[i]为结尾的递增子序列
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);

        f[n-1]=1;
        for(int i=n-2;i>=0;i--)
        {
            if(a[i]<a[i+1])
                f[i]=f[i+1]+1;
            else
                f[i]=1;
        }
        g[0]=1;
        for(int i=1;i<n;i++)
        {
            if((a[i]>a[i-1]))
                g[i]=g[i-1]+1;
            else
                g[i]=1;
        }
        set<point> s;
        s.insert(point(a[0],g[0]));
        int ans=1;
        set<point>::iterator it;
        for(int i=1;i<n;i++)
        {
            bool flag=true;
            point p=point(a[i],g[i]);
            it=s.lower_bound(p);
            if(it!=s.begin())
            {
                it--;
                ans=max(it->l+f[i],ans);
                if(g[i]<=it->l)
                    flag=false;
            }
            if(flag)
            {
                //s.erase(p);
                s.insert(p);
                it=s.find(p);
                it++;
                while(it!=s.end()&&it->l<=p.l) s.erase(it++);
            }
        }
        printf("%d\n",ans);

    }
    return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Color-based model-free tracking is a popular technique used in computer vision to track objects in video sequences. Despite its simplicity, it has demonstrated high accuracy and robustness in various applications, such as surveillance, sports analysis, and human-computer interaction. One of the key advantages of color-based model-free tracking is its real-time performance. Unlike model-based tracking, which requires complex training and computation, color-based tracking can be implemented using simple algorithms that can run in real-time on low-power devices. This makes it suitable for applications that require fast response time, such as robotics and autonomous systems. Another advantage of color-based tracking is its ability to handle occlusions and partial occlusions. Since color features are less sensitive to changes in lighting and viewing conditions, the tracker can still maintain its accuracy even when the object is partially hidden or obstructed by other objects in the scene. Critics of color-based tracking argue that it is not effective in complex scenes where the object of interest may have similar colors to the background or other objects in the scene. However, recent advancements in machine learning and deep learning have enabled the development of more sophisticated color-based tracking algorithms that can accurately detect and track objects even in challenging scenarios. In summary, color-based model-free tracking is a simple yet effective technique for tracking objects in video sequences. Its real-time performance, robustness, and ability to handle occlusions make it a popular choice for various applications. While it may not be suitable for all scenarios, advancements in machine learning are making it more effective in complex scenes.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值