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

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

在这里输入题意

【题解】

类似尺取法。 用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;
}
posted @ 2018-01-03 11:03  AWCXV  阅读(106)  评论(0编辑  收藏  举报