题目
Jessica’s a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas included in a very thick text book. The author of that text book, like other authors, is extremely fussy about the ideas, thus some ideas are covered more than once. Jessica think if she managed to read each idea at least once, she can pass the exam. She decides to read only one contiguous part of the book which contains all ideas covered by the entire book. And of course, the sub-book should be as thin as possible.
A very hard-working boy had manually indexed for her each page of Jessica’s text-book with what idea each page is about and thus made a big progress for his courtship. Here you come in to save your skin: given the index, help Jessica decide which contiguous part she should read. For convenience, each idea has been coded with an ID, which is a non-negative integer.
Input
The first line of input is an integer P (1 ≤ P ≤ 1000000), which is the number of pages of Jessica’s text-book. The second line contains P non-negative integers describing what idea each page is about. The first integer is what the first page is about, the second integer is what the second page is about, and so on. You may assume all integers that appear can fit well in the signed 32-bit integer type.
Output
Output one line: the number of pages of the shortest contiguous part of the book which contains all ideals covered in the book.
Sample Input
5
1 8 8 8 1
Sample Output
2

题意:求包含所有知识点的最小页数

#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int page[1000010],vis[1000010]={0};
set<int> s;
int main()
{int l=0,r=0,p,num=0,sum=0,len=1000010;  //因为要求最小长度,所以令初始长度最大scanf("%d",&p);for(int i=0;i<p;i++){scanf("%d",&page[i]);s.insert(page[i]);}num=s.size();  //set插入时不会插入重复数字,所以set的大小就是知识点的个数map<int,int> c;  //记录每个知识点的个数for(;;){while(r<p&&sum<num)if(c[page[r++]]++==0)  //先判断这一页的知识点是否出现过再自增sum++;if(sum<num) break;  //跳出while循环一定是不满足其中一个条件,而这条if语句中sum<num,所以r>=p,所有页数都已经遍历过,跳出循环len=min(len,r-l);if(--c[page[l++]]==0)  //去掉最左边的知识点,左边界右移(如果这个知识点在当前区间中只出现过一次,sum--)sum--;        }printf("%d\n",len);return 0;
}

POJ 3320 Jessica's Reading Problem相关推荐

  1. 尺取法 POJ 3320 Jessica's Reading Problem

    题目传送门 1 /* 2 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 3 */ 4 #include <cstdio> 5 #include &l ...

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

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

  3. POJ3320 Jessica's Reading Problem 尺取法

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

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

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

  5. 【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 ...

  6. Jessica's Reading Problem

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

  7. POJ 3320 尺取法,Hash,map标记

    1.POJ 3320 2.链接:http://poj.org/problem?id=3320 3.总结:尺取法,Hash,map标记 看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识 ...

  8. POJ 1207 The 3n + 1 problem

    题目链接:http://poj.org/problem?id=1207 题目大意:给你一个数x,规定一个函数F(x),如果x为1则F(x)==1,否则如果x是偶数,F(x)==F(x/2),x为奇数F ...

  9. poj 1681 Painter#39;s Problem(高斯消元)

    http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. 注意依据自由变元求其它解及求最优值 ...

最新文章

  1. 网易云信启动“T服务”,为开发加速
  2. Java将一段逗号分割的字符串转换成一个数组(亲测)
  3. 单选按钮步骤流程向导 js_创建令人愉快的按钮的6个步骤
  4. [css] 如何阻止:hover、:active等鼠标行为状态的触发?
  5. Android之通过VideoView控件播放一个视频出现的问题以及我的解决办法
  6. MySQL中的几类日志文件介绍
  7. margin塌陷现象div盒子嵌套盒子外边距合并现象
  8. 光网络时代网络工程师成长路线图
  9. 解决ubuntu无法连接网络问题
  10. vue项目中使用Google Analytics (谷歌统计)
  11. CTF逆向-[CISCN2018]2ex-WP_mips-32架构以及base64换表
  12. 理财入门:思维转变和资产理解以及财务自由说明。
  13. Excel数据可视化——使用图标集显示数据的意义
  14. Design Patterns - Builder
  15. 快消行业私域流量运营
  16. 使用oracle经验,ORACLE应用经验(2)
  17. qemu-kvm Hypervisor:ivshmem
  18. 计算机术语alu,计算机术语完全介绍
  19. 入门3D建模,没有美术基础你也可以学做人物角色面部造型 (下)
  20. 【020】翼辉信息董事长韩辉先生受北京工业大学邀请发表学术演讲

热门文章

  1. python数据分析岗位_python拉勾数据职位分析
  2. zoj2587 Marlon's String
  3. 基础算法4 —— 结构体(成绩统计) + 栈(模拟进制转换 + 优秀的拆分) + 指针
  4. 教你如何避开雪花算法的坑
  5. linux配置yum源
  6. 什么是AUTOSAR规范?
  7. 多吃巧克力多笑脑子会更聪明
  8. 有道English课程总结
  9. PICO《轻世界》体验:随心畅玩,洒脱创作,潜力无限
  10. B站愚人节彩蛋,UP主 “集体变绿”