题目传送门

 1 /*
 2     尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值
 3 */
 4 #include <cstdio>
 5 #include <cmath>
 6 #include <cstring>
 7 #include <algorithm>
 8 #include <set>
 9 #include <map>
10 using namespace std;
11
12 const int MAXN = 1e6 + 10;
13 const int INF = 0x3f3f3f3f;
14 int a[MAXN];
15
16 int main(void)        //POJ 3320 Jessica's Reading Problem
17 {
18     int n;
19     while (scanf ("%d", &n) == 1)
20     {
21         set<int> S;
22         for (int i=1; i<=n; ++i)
23         {
24             scanf ("%d", &a[i]);    S.insert (a[i]);
25         }
26
27         map<int, int> cnt;
28         int tot = S.size ();    int ans = n, num = 0;    int i = 1, j = 1;
29         while (1)
30         {
31             while (j <= n && num < tot)    if (cnt[a[j++]]++ == 0)    num++;
32             if (num < tot)    break;
33             ans = min (ans, j - i);
34             if (--cnt[a[i++]] == 0) num--;
35         }
36
37         printf ("%d\n", ans);
38     }
39
40     return 0;
41 }

转载于:https://www.cnblogs.com/Running-Time/p/4550274.html

尺取法 POJ 3320 Jessica's Reading Problem相关推荐

  1. POJ 3320 Jessica's Reading Problem (尺取)

    Description 给出一段长度为\(n\)的整数序列,求包含所有出现过的数的连续区间的最小长度. Input 第一行给出序列长度\(n\),第二行给出\(n\)个整数,表示这个序列.\(n \l ...

  2. POJ 3320 Jessica's Reading Problem

    题目 Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is ...

  3. Jessica‘s Reading Problem(尺取法)

    Jessica's Reading Problem (尺取法) Jessica's a very lovely girl wooed by lots of boys. Recently she has ...

  4. POJ3320 Jessica's Reading Problem 尺取法

    Jessica's Reading Problem. Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22716 Accepted ...

  5. ACM常用技巧之尺取法--POJ3061/3320/2739/2100

    尺取法:反复推进区间的开头和结尾,来求取满足条件的最小区间的方法  .    <挑战程序设计>P146 POJ3061 Subsequence Time Limit: 1000MS   M ...

  6. 【POJ - 3320 】Jessica's Reading Problem (尺取,哈希)

    题干: Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam i ...

  7. Jessica's Reading Problem

    第一部分:题目 Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. ...

  8. 尺取法 POJ 3601 Subsequence

    题目传送门 1 /* 2 题意:求连续子序列的和不小于s的长度的最小值 3 尺取法:对数组保存一组下标(起点,终点),使用两端点得到答案 4 1. 记录前i项的总和,求[i, p)长度的最小值,用二分 ...

  9. 【常用技巧精选】尺取法

    整理的算法模板合集: ACM模板 目录 1.反向扫描 1 找指定和的整数对 A.UVA1121 Subsequence B.POJ 3320 Jessica's Reading Problem C.l ...

最新文章

  1. 编写程序,输入某年某月,求该月有多少天
  2. 软件测试工作常用linux命令,软件测试工程师工作中常用的Linux命令
  3. 如何在VS2008中添加WM_INITDIALOG消息映射
  4. POJ2631 Roads in the North
  5. mysql数据库访问编程,mysql 连接数据库
  6. Cortex - M3 一些基础知识
  7. php 开源邮件系统,企业级开源邮件系统搭建的全过程
  8. Unity 设置固定移动路线
  9. 高效能人士的七个习惯读后感与总结概括-(第一章)
  10. 《css揭秘》读书笔记(1)-背景与边框
  11. android studio按键精灵,按键精灵要点讲解一 - godlike的个人页面 - OSCHINA - 中文开源技术交流社区...
  12. 仇人与恩人- 挺有意义的
  13. arctan4怎么用计算机,计算器arctan怎么按
  14. 技术分享:用JS实现的3D海浪涌动特效
  15. cdrx8如何批量导出jpg_coreldraw2019中把所有页面批量导出jpg图的解决方法
  16. OpenStack配置Cinder出现“You must set cylinders.You can do this from the extra functions menu.”解决办法
  17. type-c速度测试软件,速度篇—Type-C/USB3.0接口到底谁快_固态硬盘评测-中关村在线...
  18. kan-java, 一个能裁剪语法特性的java动态编译工具
  19. Android-开发之从掉洞到填坑之路,走进Android架构
  20. avc水平什么意思_AVC是什么?

热门文章

  1. net user test 123456 /add
  2. 第四章 jQuery文档处理
  3. 脚本方式添加全文索引
  4. SQL Server编写存储过程小工具(三)
  5. 【OpenCV/C++】KNN算法识别数字的实现原理与代码详解
  6. python教材答案字典与集合_Python——集合与字典练习
  7. linux sys伪用户作用,linux用户管理详解
  8. 把string时间取出月份_农村集市上现杀活蚌取出来的珍珠,是真的吗?为何价格这么便宜?...
  9. 时间字符串转时间戳_Python3日期与时间戳转换的几种方法
  10. OpenCV-Python实战(10)——详解 OpenCV 轮廓检测