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 ...
随机推荐
- ATmega8仿真——LED 数码管的学习
1. I/O 口的结构及特点 Atmega8 有23 个I/O 引脚,分成3 个8 位的端口B.C 和D,其中C 口只有7 位 Atmega8 采用3个8位寄存器来控制I/O端口,它们分别是:方向寄存 ...
- Docker数据卷容器
用户需要在多个容器之间共享一些数据,就可以使用数据卷容器 从阿里云仓库下载镜像(也可以自己制作一个基础进项,比如只有几M的alpine) sudo docker pull registry.cn- ...
- ncl 函数源码 gc_inout
转自气象家园论坛 经过不懈努力,终于找到了gc_inout函数的源代码,原来在这个文件里面!一颗赛艇 位置:/ncl_ncarg-6.5.0-src/ni/src/lib/nfpfort/sg_too ...
- Python学习环境搭建——VMware,Ubuntu,Anaconda,Pycharm
1.安装VMware虚拟机,版本是14.1.2(含注册码) 链接:https://pan.baidu.com/s/1ffNLONDjEMYDAenE36gRpA 密码:yazx 注:我的电脑分辨率较高 ...
- Appium安卓与环境配置
下载与安装: Appium-desktop项目地址:https://github.com/appium/appium-desktop 下载地址:https://github.com/appium/ap ...
- GsonFormat插件主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高。
GsonFormat插件主要用于使用Gson库将JSONObject格式的String 解析成实体,该插件可以加快开发进度,使用非常方便,效率高. 插件地址:https://plugins.jetbr ...
- undefined和“undefined”
说实话,它们之间的区别挺明显的,我们一般认为undefined是JavaScript提供的一个“关键字”,而“undefined”却是一个字符串,只是引号的内容和undefined一样. undefi ...
- linux后台启动程序脚本实例
启动安装的zookeeper和kafka #!/bin/bash # start zookeeper and kafka service echo "========== Start the ...
- NIO_通道之间传输数据
通道之间传输数据 transferFrom() transferTo() @Test public void test3() throws IOException { FileChannel inCh ...
- 查看linux端口对应的进程id
例如:查看占用4040端口的进程 ss -lptn 'sport = :4040'