UVa 11572 - Unique Snowflakes

来源:互联网 发布:csol mac 编辑:程序博客网 时间:2024/05/17 03:22

在给出数列中找出最长没有重复数字的数列长度。

用set检测有没有重复。


#include <iostream>#include <set>#include <algorithm>#define MAXN 1024000using namespace std;int A[MAXN];int main() {    int T;    cin >> T;    while(T--) {        int n;        cin >> n;        for(int i = 0; i < n; i++) cin >> A[i];        set<int> s;        int L = 0, R = 0, ans = 0;        while(R < n) {            while(!s.count(A[R])&& R < n) s.insert(A[R++]);            ans = max(ans, R - L);            s.erase(A[L++]);        }        cout << ans << endl;    }    return 0;}


0 0