首页 > 其他 > 详细

poj3320 Jessica's Reading Problem

时间:2017-10-02 16:35:11      阅读:211      评论:0      收藏:0      [点我收藏+]

思路:

尺取。

实现:

 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

原文:http://www.cnblogs.com/wangyiming/p/7620254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!