码迷,mamicode.com
首页 > 其他好文 > 详细

poj3320 Jessica's Reading Problem

时间:2017-10-02 16:44:54      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:思路   --   str   names   break   bre   span   map   blog   

思路:

尺取。

实现:

 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

标签:思路   --   str   names   break   bre   span   map   blog   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!