标签:blank .net blog txt style include target else div
https://vjudge.net/problem/UVA-11572
题意:输入一个长度为n的序列A,找到一个尽量长的连续子序列,使得该序列中没有相同的元素。
思路:很简单的题,也没啥好解释的了。
#include<iostream> #include<set> using namespace std; const int maxn = 1000000 + 5; int a[maxn]; int n; int maxd; void solve() { set<int> num; int L = 0, R = 0; maxd = 0; int ans = 0; while (R < n) { if (!num.count(a[R])) { ans++; num.insert(a[R]); R++; if (ans>maxd) maxd = ans; } else { num.erase(a[L]); ans--; L++; } } } int main() { //freopen("D:\\txt.txt", "r", stdin); int t; cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } solve(); cout << maxd << endl; } return 0; }
标签:blank .net blog txt style include target else div
原文地址:http://www.cnblogs.com/zyb993963526/p/6353981.html