poj3320 Jessica's Reading Problem
Description
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
Source

离散化+尺取乱搞
program rrr(input,output);
var
a,b,c:array[..]of longint;
n,m,i,j,ans,l,r,mid:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
procedure sort(q,h:longint);
var
i,j,x,t:longint;
begin
i:=q;j:=h;x:=b[(i+j)>>];
repeat
while b[i]<x do inc(i);
while x<b[j] do dec(j);
if i<=j then
begin
t:=b[i];b[i]:=b[j];b[j]:=t;
inc(i);dec(j);
end;
until i>j;
if j>q then sort(q,j);
if i<h then sort(i,h);
end;
function find(x:longint):longint;
begin
l:=;r:=m;
while l<r- do
begin
mid:=(l+r)>>;
if b[mid]>x then r:=mid- else l:=mid;
end;
if b[l]=x then exit(l) else exit(r);
end;
begin
assign(input,'r.in');assign(output,'r.out');reset(input);rewrite(output);
readln(n);
for i:= to n do begin read(a[i]);b[i]:=a[i]; end;
sort(,n);
m:=;for i:= to n do if b[i]<>b[i-] then begin inc(m);b[m]:=b[i]; end;
for i:= to n do a[i]:=find(a[i]);
fillchar(c,sizeof(c),);i:=;
for j:= to n do
begin
inc(c[a[j]]);
if c[a[j]]= then inc(i);
if i=m then break;
end;
ans:=j;
for i:= to n do
begin
dec(c[a[i-]]);
while (j<n) and (c[a[i-]]=) do begin inc(j);inc(c[a[j]]); end;
if c[a[i-]]= then break;
ans:=min(ans,j-i+);
end;
write(ans);
close(input);close(output);
end.
poj3320 Jessica's Reading Problem的更多相关文章
- POJ3320 Jessica's Reading Problem(尺取+map+set)
POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...
- POJ3320 Jessica's Reading Problem 2017-05-25 19:55 38人阅读 评论(0) 收藏
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12346 Accep ...
- poj3320 Jessica's Reading Problem(尺取思路+STL)
https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...
- poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)
这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...
- POJ3320 Jessica's Reading Problem
Bryce1010模板 #include <stdio.h> #include <string.h> #include <stdlib.h> #include &l ...
- 【二分】Jessica's Reading Problem
[POJ3320]Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1309 ...
- Jessica's Reading Problem——POJ3320
Jessica's Reading Problem——POJ3320 题目大意: Jessica 将面临考试,她只能临时抱佛脚的在短时间内将课本内的所有知识点过一轮,课本里面的P个知识点顺序混乱,而且 ...
- Greedy:Jessica's Reading Problem(POJ 3320)
Jessica's Reading Problem 题目大意:Jessica期末考试临时抱佛脚想读一本书把知识点掌握,但是知识点很多,而且很多都是重复的,她想读最少的连续的页数把知识点全部掌握(知识点 ...
- POJ 3320 Jessica's Reading Problem
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6001 Accept ...
随机推荐
- Object C学习笔记4-内存管理
Object-C的内存管理和.NET有些不一样,.NET的内存回收机制是使用GC自动处理回收,而Object-C本质上还是C语言,所以很多时候还是需要手动去管理内存回收. 1. Object-C生成一 ...
- Python中的dict字典的用法
Python中的字典特点: 速度快,内部使用二分查找的方式 可以用来存储大量的关系型数据 字典是无序的 字典的定义方式: dic = dict(name =”zhangsan”, age = 19) ...
- Python对中文的支持
在Python中,经常会出现中文,出现中文有时候会报错,这时候很多新手在处理中文编码的时候会有点不知所措. Python主要有2.x和3.x版本两个区别,在3.x版本中,已经支持中文直接开发,而不需要 ...
- 第1章 Linux命令行简介
1.1 Linux命令行概述 1.2 在Linux命令行下查看命令帮助 1.3 Linux关机.重启.注销命令 1.4 老男孩的运维思想 1.1 Linux命令行概述 1.1.1 Linux命令行的作 ...
- 将jira添加至开机自启动
东北证券网金部jira项目管理系统,经常莫名挂掉,于是乎将jira服务加入开机自启动. jira.sh脚本代码如下: #!/bin/sh # chkconfig: # description:jira ...
- 傻瓜式搭建私有云就用这两组合:宝塔+kodexplorer
介绍 宝塔面板:是一款linux/windows平台均可使用的服务器管理软件,自带环境包,主要基于centos操作系统,可一键包装nginx.apache.php.mysql.pureftpd.php ...
- systemctl status ssh.service 服务重启出现报错
Case: ubuntu在从Ubuntu 16.04 LTS 升级到18.04 的时候,执行 do-release-upgrade -d 后,发现ssh无法登陆服务器, Solution: 1.通过s ...
- Metasploit漏洞利用,三个入侵主机实战案例
受害者主机 windows2003 ie模拟工具ietest ie5.5/6/7/ 漏洞:MS10_002,MS10_018,MS12-020 ---------------------------- ...
- 第十一次ScrumMeeting博客
第十一次ScrumMeeting博客 本次会议于11月29日(三)22时整在3公寓725房间召开,持续30分钟. 与会人员:刘畅.辛德泰张安澜.赵奕.方科栋. 1. 每个人的工作(有Issue的内容和 ...
- fetch err : "Body not allowed for GET or HEAD requests"
在使用 fetch 的时候 报了 "Body not allowed for GET or HEAD requests" 这个错. 代码如下: 一番google , 找到答案了. ...