其他分享
首页 > 其他分享> > POJ-3320 Jessica's Reading Problem

POJ-3320 Jessica's Reading Problem

作者:互联网

Jessica's Reading Problem

尺取法模板题

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
const ll maxn = 1000000 + 10;
const ll inf = 1e17 + 10;
map<int, int>vis;
int num[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    set<int>s;
    for(int i=0; i<n; i++)
    {
        scanf("%d", &num[i]);
        s.insert(num[i]);
    }
    int l = 0, r = 0, ans = n, cnt = 0;
    while(1)
    {
        while(r < n && cnt < s.size())
        {
            if(vis[num[r++]]++ == 0)
                cnt++;
        }
        while(vis[num[l]] != 1)
            vis[num[l++]]--;
        if(cnt < s.size()) break;
        ans = min(ans, r - l);
        vis[num[l++]]--;
        cnt--;
    }
    printf("%d\n", ans);

    return 0;
}

标签:Reading,const,int,ll,long,3320,Problem,include
来源: https://www.cnblogs.com/dgsvygd/p/16265194.html