首页 > 代码库 > POJ 3320

POJ 3320

#include <iostream>#include <set>#include <map>using namespace std;unsigned int P;set<unsigned int> ideaSet;unsigned int idea[1000001];int numOfIdea;int main(){    scanf("%ud", &P);    for(int i = 0; i < P; ++i)    {        scanf("%ud", &idea[i]);        ideaSet.insert(idea[i]);    }        numOfIdea = ideaSet.size();    int num = 0;    map<unsigned int, unsigned int> mp;    int s = 0;    int t = 0;    int res = P;    for(;;)    {        while(num < numOfIdea && t < P)        {            if(mp[idea[t++]]++ == 0)            {                num++;            }        }        if(num < numOfIdea)            break;        res = min(res, t - s);        if(--mp[idea[s++]] == 0)            --num;    }    printf("%d\n", res);        return 0;} 

 

POJ 3320