| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大水题#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
using namespace std;
const int INF=0x4fffffff;
const int EXP=1e-6;
const int MS=1000005;
int page[MS];
set<int> s;
map<int,int> mp;
int n;
void solve()
{
int cnt=s.size();
int ans=n;
int num=0;
int s=0,t=0;
while(1)
{
while(t<n&&num<cnt)
{
if(mp[page[t++]]++==0)
num++;
}
if(num<cnt)
break;
ans=min(ans,t-s);
if(--mp[page[s++]]==0)
num--;
}
printf("%d\n",ans);
}
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&page[i]);
s.insert(page[i]);
}
solve();
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator