题意:

每页书都对应一个知识点,问最少看连续的多少页,才能把所有知识点都看完?

分析:

《挑战程序设计竞赛》介绍的尺取法反复推进区间的开头和结尾,来求取满足条件的最小区间,先确定好一个满足条件的区间,然后不断往后移,找满足条件的区间。

代码:

#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
const int maxn = 1e6+5;
map<int, int>cnt;
int a[maxn];
set<int>all;
int main (void)
{
int P;scanf("%d",&P);
for(int i = 0; i < P; i++) {
scanf("%d",&a[i]);
all.insert(a[i]);
}
int si =all.size();
int last = 1, s = 0, res, num = 0;
for(int i = 0; i < P; i++){
if(cnt[a[i]]++==0) num++;
if(num==si){
s = i + 1;
break;
}
}
res = s; while(last < P){
if(cnt[a[last-1]]==1){
while(s<P&&a[s]!=a[last-1]) cnt[a[s++]]++;
if(s==P) break;
else s++;
}else cnt[a[last-1]]--; res = min(res, s - last);
last++;
}
printf("%d\n",res); }

POJ 3320_Jessica's Reading Problem的更多相关文章

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

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

  2. Jessica's Reading Problem POJ - 3320

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

  3. A - Jessica's Reading Problem POJ - 3320 尺取

    A - Jessica's Reading Problem POJ - 3320 Jessica's a very lovely girl wooed by lots of boys. Recentl ...

  4. Greedy:Jessica's Reading Problem(POJ 3320)

    Jessica's Reading Problem 题目大意:Jessica期末考试临时抱佛脚想读一本书把知识点掌握,但是知识点很多,而且很多都是重复的,她想读最少的连续的页数把知识点全部掌握(知识点 ...

  5. POJ 3320 Jessica's Reading Problem

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

  6. POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法

    Subsequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13955   Accepted: 5896 Desc ...

  7. POJ 3320 Jessica's Reading Problem 尺取法/map

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

  8. POJ:3320-Jessica's Reading Problem(尺取法)

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

  9. POJ 3220 Jessica's Reading Problem

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

随机推荐

  1. hihocoder offer收割编程练习赛12 C 矩形分割

    思路: 模拟,深搜. 实现: #include <iostream> #include <cstdio> #include <string> using names ...

  2. [BZOJ1257][CQOI2007]余数之和sum 数学+分块

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1257 题目所求为$$Ans=\sum_{i=1}^nk%i$$ 将其简单变形一下$$Ans ...

  3. git 出现 The current branch is not configured for pull No value for key branch.master.merge found in configuration

    以下是我在网上找到的不错的文章,我参考后已解决我的问题: http://my.oschina.net/robinsonlu/blog/144085 http://www.cnblogs.com/zha ...

  4. es6 基础语法

    var c= 1 <!--都不能预解析-->let a = 1//const不能修改变量const b = 1 箭头函数 =>var c = function fun(a, b) { ...

  5. CHECKPOINT - 强制一个事务日志检查点

    SYNOPSIS CHECKPOINT DESCRIPTION 描述 预写式日志(Write-Ahead Logging (WAL))缺省时在事务日志中每隔一段时间放一个检查点. (要调整这个原子化的 ...

  6. git 提交运用vim编辑器

    git  commit -m 默认使用nano,觉得不爽,改成vim吧.在 .gitconfig (在根目录下)的  [core] 段中加上 editor=vim . 或:$git config -- ...

  7. freenas 系统可能存在的bug

    1.portal 中ip端口显示有问题. 2.创建extend/target映射之后重启iscsi服务有的时候不能启动. 3.后台/usr /etc 重启系统会自动还原.

  8. 解决idea开启tomcat报Configuration Error: deployment source 'xxx:war exploded' is not valid错

    这个问题比较棘手, 出错了的时候Tomcat服务器不能正常运行, 导致网页无法打开, 小组成员都说"Tomcat炸了"! 好在这个这个xml配置文件是自动生成的,重新生成一下就好了 ...

  9. UTF-8,UTF-16

    UTF是 Unicode Translation Format,即把Unicode转做某种格式的意思. 在Unicode基本多文种平面定义的字符(无论是拉丁字母.汉字或其他文字或符号),一律使用2字节 ...

  10. IIS更改根目录

    服务器中打开IIS管理器,选择网站,再选展开后的站点,点击右边高级设置,最后更改弹框中的物理地址即可: