poj3320 Jessica's Reading Problem
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj3320 Jessica's Reading Problem相关的知识,希望对你有一定的参考价值。
思路:
尺取。
实现:
1 #include <cstdio> 2 #include <iostream> 3 #include <map> 4 using namespace std; 5 const int INF = 0x3f3f3f3f; 6 int a[1000005]; 7 map<int, int> mp; 8 int main() 9 { 10 int n; 11 scanf("%d", &n); 12 for (int i = 0; i < n; i++) { scanf("%d", &a[i]); mp[a[i]]++; } 13 int i = 0, j = 0, ans = INF, tot = mp.size(); 14 mp.clear(); 15 while (true) 16 { 17 while (j < n && (int)mp.size() < tot) { mp[a[j]]++; j++; } 18 if (j == n && i == j) break; 19 if ((int)mp.size() == tot) ans = min(ans, j - i); 20 mp[a[i]]--; if (!mp[a[i]]) mp.erase(a[i]); 21 i++; 22 } 23 cout << ans << endl; 24 return 0; 25 }
以上是关于poj3320 Jessica's Reading Problem的主要内容,如果未能解决你的问题,请参考以下文章
POJ - 3320 Jessica's Reading Problem
(尺取法)POJ 3320 Jessica's Reading Problem
POJ 3320Jessica's Reading Problem (尺取法)
poj3320 Jessica's Reading Problem