您的位置:首页 > 产品设计 > UI/UE

uva 11572 Unique Snowflakes (唯一的雪花)

2017-08-12 13:48 381 查看
题目链接

题意输入一个长度为n 的序列,找到一个尽量长的连续子序列Al~Ar,使得该序列中没有相同元素。

分析 用左右端点去遍历 然后用set查重。

#include<bits/stdc++.h>
using namespace std;
int a[1000005],len,l,r,t,n;
int main (void){
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
set<int>s;
l=0;r=0;len=0;
while(r<n){
while( r<n && !s.count(a[r])) s.insert(a[r++]);
len=max(len,r-l);
s.erase(a[l++]);
}
cout<<len<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: