尺取法 POJ 3320 Jessica's Reading Problem
/*
尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值
*/
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std; const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN]; int main(void) //POJ 3320 Jessica's Reading Problem
{
int n;
while (scanf ("%d", &n) == )
{
set<int> S;
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]); S.insert (a[i]);
} map<int, int> cnt;
int tot = S.size (); int ans = n, num = ; int i = , j = ;
while ()
{
while (j <= n && num < tot) if (cnt[a[j++]]++ == ) num++;
if (num < tot) break;
ans = min (ans, j - i);
if (--cnt[a[i++]] == ) num--;
} printf ("%d\n", ans);
} return ;
}
尺取法 POJ 3320 Jessica's Reading Problem的更多相关文章
- 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 3320 Jessica's Reading Problem
Jessica's Reading Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6001 Accept ...
- POJ 3320 Jessica's Reading Problem 尺取法
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
- POJ 3320 Jessica's Reading Problem (尺取法)
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is co ...
- 题解报告:poj 3320 Jessica's Reading Problem(尺取法)
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- poj 3320 Jessica's Reading Problem(尺取法)
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- POJ 3320 Jessica's Reading Problem (尺取法,时间复杂度O(n logn))
题目: 解法:定义左索引和右索引 1.先让右索引往右移,直到得到所有知识点为止: 2.然后让左索引向右移,直到刚刚能够得到所有知识点: 3.用右索引减去左索引更新答案,因为这是满足要求的子串. 4.不 ...
随机推荐
- cef3的各个接口你知道几个
CEF3基本的框架包含C/C++程 序接口,通过本地库的接口来实现,而这个库则会隔离宿主程序和 Chromium&Webkit的操作细节.它在浏览器控件和宿主程序之间提供紧密的整合,它支持用户 ...
- Prime Distance(二次筛素数)
Description The branch of mathematics called number theory is about properties of numbers. One of th ...
- redux-saga 异步流
前言 React的作用View层次的前端框架,自然少不了很多中间件(Redux Middleware)做数据处理, 而redux-saga就是其中之一,目前这个中间件在网上的资料还是比较少,估计应用的 ...
- mac 通过 终端 ssh 远程连接 centos 服务器
mac 通过 终端 ssh 远程连接 centos 服务器 在终端下输入 ssh -l root 204.74.*.* 就可以连接了,这是端口没变的情况,还是原来的22 ssh -p 448 ...
- canvas鼠标点击划线
今天学习了canvas,打算写一个鼠标划线的效果. <!DOCTYPE html> <html lang="en"> <head> <me ...
- 加载之ready和onload
页面加载完成有两种事件,一是ready,表示文档结构已经加载完成(不包含图片等非文字媒体文件),二是onload,指示页面包含图片等文件在内的所有元素都加载完成. 真不知道这个标题该怎么取,暂时就先凑 ...
- 【转】Android性能优化-过度绘制解决方案
转载请注明出处:http://blog.csdn.net/a740169405/article/details/53896497 过度绘制: 屏幕上某一像素点在一帧中被重复绘制多次,就是过度绘制. 下 ...
- AutoIT: ControlCommand是一个非常重要的指令
ControlCommand可以确定窗口中的复选框是否选中状态,然后可以对这些复选框进行操作.可以对ComboBox和ListBox进行操作如选择下拉框的某个选项 if WinExists(" ...
- linux 远程杀掉进程
转自http://blog.csdn.net/tengdazhang770960436/article/details/53906263 第一步:获取进程号 pid=$(ssh root@$remot ...
- Tool:XMind
ylbtech-Tool:XMind XMind 是一款非常实用的商业思维导图软件,应用全球最先进的Eclipse RCP 软件架构,全力打造易用.高效的可视化思维软件,强调软件的可扩展.跨平台.稳定 ...