poj 3320 技巧/尺取法 map标记
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
题意:求最短的 连续的子序列 使得出现所给序列中所有不同的数 输出长度
题解:记录左边界head=1
  每次将右边位置向右移动一下,当出现a[i]==a[head]时尝试移动左边界
  什么时候能移动呢?当最左边的数的计数大于1时移动 也就是最左边的数在当前区间出现次数>1
  取满足条件的区间长度的最小值;
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<cmath>
#define ll long long
#define PI acos(-1.0)
#define mod 1000000007
using namespace std;
int p;
int a[];
int zong=;
map<int,int>mp;
int main()
{
while(~scanf("%d",&p))
{
mp.clear();
zong=;
for(int i=; i<=p; i++)
{
scanf("%d",&a[i]);
if(mp[a[i]]==)
zong++;
mp[a[i]]++;
}
mp.clear();
int ans=;
mp[a[]]=;
ans++;
int head=;
int maxn=p;
for(int i=; i<=p; i++)
{
if(mp[a[i]]==)
ans++;
mp[a[i]]++;
if(a[i]==a[head])
{
while(mp[a[head]]>)
{
mp[a[head]]--;
head++;
}
}
if(ans==zong)
maxn=min(maxn,i-head+);
}
printf("%d\n",maxn);
}
return ;
}
poj 3320 技巧/尺取法 map标记的更多相关文章
- Jessica's Reading Problem POJ - 3320(尺取法2)
		题意:n页书,然后n个数表示各个知识点ai,然后,输出最小覆盖的页数. #include<iostream> #include<cstdio> #include<set& ... 
- poj  3320    jessica's Reading PJroblem   尺取法 -map和set的使用
		jessica's Reading PJroblem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9134 Accep ... 
- POJ 3061 Subsequence 尺取法 POJ 3320 Jessica's Reading Problem map+set+尺取法
		Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13955 Accepted: 5896 Desc ... 
- POJ 3320 Jessica's Reading Problem 尺取法/map
		Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7467 Accept ... 
- POJ——3061Subsequence(尺取法或二分查找)
		Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11224 Accepted: 4660 Desc ... 
- poj 3061 题解(尺取法|二分
		题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 ... 
- POJ 3061 Subsequence 尺取法
		转自博客:http://blog.chinaunix.net/uid-24922718-id-4848418.html 尺取法就是两个指针表示区间[l,r]的开始与结束 然后根据题目来将端点移动,是一 ... 
- POJ 3061 Subsequence(尺取法)
		Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18145 Accepted: 7751 Desc ... 
- POJ:3061-Subsequence(尺取法模板详解)
		Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18795 Accepted: 8043 Descript ... 
随机推荐
- Oracle内置函数内容整理
			--绝对值select abs(-100) from dual; --取余select mod(8,3) from dual; --取整,大于该数的最小整数(上限值)select ceil(12.0) ... 
- Apache启用性能优化——启用Gzip,JS压缩
			#Add deflate module for enable GZIP function LoadModule deflate_module modules/mod_deflate.so #A ... 
- win7 摄像头驱动软件找不到,只有sys文件
			有的驱动只有sys文件,但是仍然可以在qq视频等用,只是找不到amcap.exe等可执行文件, 因为没有摄像头软件,下载一个安装上即可 
- for update造成的Oracle锁表与解锁
			我遇到的情况: 当使用select语句查询表时,后面跟着for update , select * from table for update 当修改表中数据,但是没有commit就关掉PL/SQL, ... 
- (DFS)hdoj1241-Oil Deposit
			#include<cstdio> ][]; ][]={{,},{,-},{,},{-,},{,},{,-},{-,},{-,-}},cnt; void dfs(int x,int y) { ... 
- [开发笔记]-WindowsService服务程序开发
			Windows服务:Microsoft Windows 服务(即,以前的 NT服务)使您能够创建在它们自己的 Windows 会话中可长时间运行的可执行应用程序.这些服务可以在计算机启动时自动启动,可 ... 
- C#常用实例
			1 時間 1.1 顯示在走的時間 控件:TextBox為顯示日期時間,命名為txtDateTimer Timer為時鐘,命名為time private void dtDateTimer_Tick(ob ... 
- C# 开发XML Web Service与Java开发WebService
			一.web service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量 ... 
- 算法(第4版)-1.1.7 API
			总结:本小姐讲述了API的定义.作用以及一些Java库的举例. 重点: 1.API的目的是将调用和实现分离:除了API中给出的信息,调用者不需要知道实现的其他细节,而实现也不应考虑特殊的应用场景. 
- Ubuntu系统下运行Eclipse出现找不到jre的问题的解决方法
			在Ubuntu的某些版本下,比如10.10,会出现以下奇怪问题: 1. 安装jdk 我下载的jdk是bin格式的,直接运行解压,得到一个文件夹. 这个文件夹作为jdk的安装目录,可以拷贝到任意目录. ... 
