zoukankan      html  css  js  c++  java
  • uva 11572 唯一的雪花

    题目大意:

    一个数列a,找到一个尽量长的连续子序列 ax 到 ay,使得该系列中没有相同的元素,求数列长度

    思路:

    滑动窗口

    每次判断窗口内是否有重复即可

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstdlib>
     6 #include<cstring>
     7 #include<queue>
     8 #include<vector>
     9 #define inf 2147483611
    10 #define ll long long
    11 #define MAXN 1010101
    12 #define MOD
    13 using namespace std;
    14 inline ll read()
    15 {
    16     ll x=0,f=1;
    17     char ch;ch=getchar();
    18     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
    19     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
    20     return x*f;
    21 }
    22 int l,r,ans,n,a[MAXN],hash[MAXN];
    23 int main()
    24 {
    25     n=read();
    26     l=r=1;
    27     for(int i=1;i<=n;i++) a[i]=read();
    28     while(r<n)
    29     {
    30         while(r<n)
    31         {
    32             if(!hash[a[r+1]]) hash[a[r++]]++;
    33             else break;
    34         }
    35         ans=max(ans,r-l+1);
    36         while(hash[a[r+1]]) {hash[a[l++]]--;}
    37     }
    38     printf("%d",ans);
    39 }
    View Code

     

  • 相关阅读:
    GSON -JSON 反序列化-多节点名称支持
    Jedis 分片原理
    闭锁-CountDownLatch
    XML序列化及反序列化
    用GIT操作SVN
    报表worker-CPU使用率过高原因排查
    二.PlantUML 之活动图
    一.PlantUML 与 IDEA 集成
    ArrayList
    VI常用命令
  • 原文地址:https://www.cnblogs.com/yyc-jack-0920/p/7629020.html
Copyright © 2011-2022 走看看