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

【例题 8-7 UVA - 11572】Unique Snowflakes

2018-01-03 11:03 323 查看

【链接】 我是链接,点我呀:)
【题意】


在这里输入题意

【题解】


类似尺取法。
用set判断这段区间有没有重复的数字。
有的话,就把头节点的那个数字删掉,直到没有为止。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6;

int n,a[N+10];
set<int> myset;

int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
myset.clear();
cin >> n;
for (int i = 1;i <= n;i++) cin >> a[i];
int l = 1,ma = 1;
myset.insert(a[1]);
for (int i = 2;i <= n;i++){
while(myset.find(a[i])!=myset.end()) myset.erase(a[l++]);
myset.insert(a[i]);
ma = max(ma,i-l+1);
}
cout <<ma<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: