Bryce1010模板

#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的更多相关文章

  1. POJ3320 Jessica's Reading Problem(尺取+map+set)

    POJ3320 Jessica's Reading Problem set用来统计所有不重复的知识点的数,map用来维护区间[s,t]上每个知识点出现的次数,此题很好的体现了map的灵活应用 #inc ...

  2. 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 ...

  3. poj3320 Jessica's Reading Problem(尺取思路+STL)

    https://vjudge.net/problem/POJ-3320 尺取法,要想好组织方式. 又被卡了cin.. #include<iostream> #include<cstd ...

  4. poj3320 Jessica's Reading Problem

    Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...

  5. poj3061 Subsequence&&poj3320 Jessica's Reading Problem(尺取法)

    这两道题都是用的尺取法.尺取法是<挑战程序设计竞赛>里讲的一种常用技巧. 就是O(n)的扫一遍数组,扫完了答案也就出来了,这过程中要求问题具有这样的性质:头指针向前走(s++)以后,尾指针 ...

  6. 【二分】Jessica's Reading Problem

    [POJ3320]Jessica's Reading Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1309 ...

  7. Jessica's Reading Problem——POJ3320

    Jessica's Reading Problem——POJ3320 题目大意: Jessica 将面临考试,她只能临时抱佛脚的在短时间内将课本内的所有知识点过一轮,课本里面的P个知识点顺序混乱,而且 ...

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

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

  9. POJ 3320 Jessica's Reading Problem

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

随机推荐

  1. 【转载】epoll与select/poll的区别总结

    因为这道题目经常被问到.干脆总结一下,免得遗漏了. 参考文章:http://www.cnblogs.com/qiaoconglovelife/p/5735936.html 1 本质上都是同步I/O 三 ...

  2. [Angular] Refactor Angular Component State Logic into Directives

    Allow the base toggle to be a tag (<toggle>) or attribute (<div toggle>). The <toggle ...

  3. 【原创】PHP扩展开发入门

    PHP扩展开发入门 作者:wf (360电商技术组) 在我们编写自己的第一个php扩展之前,先了解一下php的总体架构和执行机制. php的架构如图1所看到的. 当中一个重要的就是SAPI(serve ...

  4. Office EXCEL 复制粘贴 变成 #value,#REF!,#DIV怎么办

    这些都是由于相对引用造成的,如下所示,我鼠标点进去之后变成了I10/L10,当数字和文字或空单元格进行加减乘除的运算就会出现这种问题   使用选择性粘贴,只粘贴数值即可.

  5. router-link的a样式变成div样式元素属性

    <router-link tag="div" :to="itemChild.path"><span>{{itemChild.name}} ...

  6. ImageLoader实现图片异步载入

    ImageLoader是一个广泛使用的图片库,在向网络请求图片时.使用imageView和smartView常会产生outofmemory错误,这时ImageLoader能够起到非常大的作用.主要有例 ...

  7. [IT学习]Python pandas 学习

    今天学习pandas来处理数据,结果用python 3.5.0的shell来调试,总是报错. 报错中包含如下字样: Traceback (most recent call last): File &q ...

  8. iOS开发——高级篇——Runloop相关一

    一.什么是runLoop 1.说白了,runloop就是运行循环 2.runloop,他是多线程的法宝 通常来讲,一个线程一次只能执行一个任务,执行完之后就退出线程.但是,对于主线程是不能退出的,因此 ...

  9. Java类加载机制?

    深入研究Java类加载机制 类加载是Java程序运行的第一步,研究类的加载有助于了解JVM执行过程,并指导开发者采取更有效的措施配合程序执行. 研究类加载机制的第二个目的是让程序能动态的控制类加载,比 ...

  10. 设置Table边框的CSS

    <!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid blac ...