zoukankan      html  css  js  c++  java
  • 相同子序列集合

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3053

    题意:给两段序列A和B,能找到多少(A' , B')两个集合相同,且A'为A 的子序列,B‘为B的子序列。

    思路:暴力枚举A序列,将B序列的值用下标作标记。如果标记最大与最小差值加一等于a序列个数,就符合条件。

    #include<cstdio>
    #include<cmath>
    #include<map>
    #include<cstring>
    #include <iostream>
    #include<algorithm>
    using namespace std;
    const int MAX = 1e5 + 10;
    typedef long long LL;
    int a[100009];
    int vis[100009];
    int main()
    {
        int n ;
        while(~scanf("%d" , &n) && n)
        {
           // memset(vis , 0 , sizeof(vis));
            for(int i = 1 ; i <= n ; i++)
            {
                scanf("%d" , &a[i]);
            }
            for(int i = 1 ; i <= n ; i++)
            {
                int t ;
                scanf("%d" , &t);
                vis[t] = i ;
            }
            int ans = 0 ;
            for(int i = 1 ; i <= n ; i++)
            {
                int max = vis[a[i]];
                int min = vis[a[i]];
                int num = 1 ;
                for(int j = i + 1 ; j <= n ; j++)
                {
                    if(vis[a[j]] < min)
                        min = vis[a[j]];
                    else if(vis[a[j]] > max)
                        max = vis[a[j]];
                    num++;
                    if(num == max - min + 1)
                        ans++ ;
                }
            }
            printf("%d
    " , ans);
        }
    
    
        return 0;
    }
  • 相关阅读:
    流光shader 和 流光+扭曲shader
    unity3d android动态更新dll
    Shader之溶解效果的几种实现方法
    我的第一个法线贴图
    windows 函数
    MFC 消息框
    C++ MFC棋牌类小游戏day1
    C++STL 预定义函数对象和函数适配器
    C++STL 函数对象和谓词
    C++STL 算法
  • 原文地址:https://www.cnblogs.com/nonames/p/11311649.html
Copyright © 2011-2022 走看看