POJ3320 Jessica's Reading Problem
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <math.h>
using namespace std;
#pragma warning(disable:4996)
typedef long long LL;
#define cinInt(a) scanf("%d",&a)
#define cinInt64(a) scanf("%I64d",&a)
#define cinDouble(a) scanf("%lf",&a)
const int INF = 1 << 30;
void input(int &x)
{
char ch = getchar();
while(ch>'9' || ch<'0')
ch = getchar();
x = 0;
while(ch>='0' && ch<='9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
}
map<int,int> vis;
int a[10000000+10];
int main()
{
int n,i;
int cnt = 0;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; ++i)
{
input(a[i]);
if(!vis[a[i]])
{
vis[a[i]]++;
cnt++;//知识点的个数
}
}
vis.clear();
int ans = INF;
int s=0,t=0,cnt2=0;
for(;;)
{
while(t<n && cnt2<cnt)//一定要找够cnt个知识点才能够跳出循环
{
if(vis[a[t]]==0)
cnt2++;
vis[a[t++]]++;
}
if(cnt2<cnt)
break;
ans = min(ans,t-s);
vis[a[s]]--;
if(!vis[a[s++]])//因为区间的缩小,导致知识点的个数减少
cnt2--;
}
printf("%d\n",ans);
}
return 0;
}
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 ...
- poj3320 Jessica's Reading Problem
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)
这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...
- 【二分】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 ...
随机推荐
- javascript 自定义错误处理
php 中是可以自定义程序的错误和异常处理函数的(handler).于是,我在想,javascript 中是否也存在和PHP中一样的异常和错误处理函数呢? try{}catch(){} 这种捕捉异常和 ...
- Office EXCEL 如何实现在单元格内换行
按A/T+回车可以实现手动换行
- Navicat for MySQL出现#1045 错误怎么办
#1045 - Access denied for user 'root'@'localhost' (using password: NO)这是因为你连接的时候没有密码或者密码没改对导致的.如下图所示 ...
- 异或巧用:Single Number
异或巧用:Single Number 今天刷leetcode,碰到了到题Single Number.认为解答非常巧妙,故记之... 题目: Given an array of integers, ev ...
- 为经典版eclipse添加web and JavaEE插件
地址:http://download.eclipse.org/releases/juno. 选择Web,XML,Java EE and OSGI Enterprise Development,之后ne ...
- 【JAVA】java中Future、FutureTask的使用
如今的系统基本都是分布式的,各个系统各司其职的,不可能一个系统干了全部系统的事. 所以系统之间的交互就越来越多了.那么系统之间的交互仅仅有通过网络来交互了,而网络必定会存在延时的情况. 比方A系统的一 ...
- 在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作
在云服务器 ECS Linux CentOS 7 下重启服务不再通过 service 操作,而是通过 systemctl 操作. 操作说明如下: 1. 查看 sshd 服务是否启动: 看到上述信息就 ...
- [英语学习]王秒同学《21天TED英语精练团》
第一个分享: Chris Anderson的TED's secret to great public speaking(英音). There's no single formula for a gre ...
- ExtJs布局中,控件如何水平居中?
如此即可,有图有代码有j8: var formGridHead = Ext.create('Ext.form.Panel', { id: 'MyGridHead', region: 'north', ...
- DRF的认证,频率,权限
1,DRF的认证 初识认证:浏览器是无状态的,一次导致每次发的请求都是新的请求,所以每次请求,服务器都会进行校验,这样就很繁琐,这趟我们就需要给每一个用户登录后一个新的标识,浏览器每次都会带着这个唯一 ...