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;
    }
  • 相关阅读:
    套接字(socket)
    网络编程
    面向对象之反射
    面向对象的多态
    面向对象之封装
    面向对象之继承
    面向对象之编程思想
    python中的包
    python中的序列化模块
    正则表达式
  • 原文地址:https://www.cnblogs.com/nonames/p/11311649.html
Copyright © 2011-2022 走看看