尺取法 POJ 3320 Jessica's Reading Problem
题目传送门
1 /* 2 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 3 */ 4 #include <cstdio> 5 #include <cmath> 6 #include <cstring> 7 #include <algorithm> 8 #include <set> 9 #include <map> 10 using namespace std; 11 12 const int MAXN = 1e6 + 10; 13 const int INF = 0x3f3f3f3f; 14 int a[MAXN]; 15 16 int main(void) //POJ 3320 Jessica's Reading Problem 17 { 18 int n; 19 while (scanf ("%d", &n) == 1) 20 { 21 set<int> S; 22 for (int i=1; i<=n; ++i) 23 { 24 scanf ("%d", &a[i]); S.insert (a[i]); 25 } 26 27 map<int, int> cnt; 28 int tot = S.size (); int ans = n, num = 0; int i = 1, j = 1; 29 while (1) 30 { 31 while (j <= n && num < tot) if (cnt[a[j++]]++ == 0) num++; 32 if (num < tot) break; 33 ans = min (ans, j - i); 34 if (--cnt[a[i++]] == 0) num--; 35 } 36 37 printf ("%d\n", ans); 38 } 39 40 return 0; 41 }
转载于:https://www.cnblogs.com/Running-Time/p/4550274.html
尺取法 POJ 3320 Jessica's Reading Problem相关推荐
- POJ 3320 Jessica's Reading Problem (尺取)
Description 给出一段长度为\(n\)的整数序列,求包含所有出现过的数的连续区间的最小长度. Input 第一行给出序列长度\(n\),第二行给出\(n\)个整数,表示这个序列.\(n \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 ...
- Jessica‘s Reading Problem(尺取法)
Jessica's Reading Problem (尺取法) Jessica's a very lovely girl wooed by lots of boys. Recently she has ...
- POJ3320 Jessica's Reading Problem 尺取法
Jessica's Reading Problem. Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22716 Accepted ...
- ACM常用技巧之尺取法--POJ3061/3320/2739/2100
尺取法:反复推进区间的开头和结尾,来求取满足条件的最小区间的方法 . <挑战程序设计>P146 POJ3061 Subsequence Time Limit: 1000MS M ...
- 【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 i ...
- Jessica's Reading Problem
第一部分:题目 Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. ...
- 尺取法 POJ 3601 Subsequence
题目传送门 1 /* 2 题意:求连续子序列的和不小于s的长度的最小值 3 尺取法:对数组保存一组下标(起点,终点),使用两端点得到答案 4 1. 记录前i项的总和,求[i, p)长度的最小值,用二分 ...
- 【常用技巧精选】尺取法
整理的算法模板合集: ACM模板 目录 1.反向扫描 1 找指定和的整数对 A.UVA1121 Subsequence B.POJ 3320 Jessica's Reading Problem C.l ...
最新文章
- 编写程序,输入某年某月,求该月有多少天
- 软件测试工作常用linux命令,软件测试工程师工作中常用的Linux命令
- 如何在VS2008中添加WM_INITDIALOG消息映射
- POJ2631 Roads in the North
- mysql数据库访问编程,mysql 连接数据库
- Cortex - M3 一些基础知识
- php 开源邮件系统,企业级开源邮件系统搭建的全过程
- Unity 设置固定移动路线
- 高效能人士的七个习惯读后感与总结概括-(第一章)
- 《css揭秘》读书笔记(1)-背景与边框
- android studio按键精灵,按键精灵要点讲解一 - godlike的个人页面 - OSCHINA - 中文开源技术交流社区...
- 仇人与恩人- 挺有意义的
- arctan4怎么用计算机,计算器arctan怎么按
- 技术分享:用JS实现的3D海浪涌动特效
- cdrx8如何批量导出jpg_coreldraw2019中把所有页面批量导出jpg图的解决方法
- OpenStack配置Cinder出现“You must set cylinders.You can do this from the extra functions menu.”解决办法
- type-c速度测试软件,速度篇—Type-C/USB3.0接口到底谁快_固态硬盘评测-中关村在线...
- kan-java, 一个能裁剪语法特性的java动态编译工具
- Android-开发之从掉洞到填坑之路,走进Android架构
- avc水平什么意思_AVC是什么?
热门文章
- net user test 123456 /add
- 第四章 jQuery文档处理
- 脚本方式添加全文索引
- SQL Server编写存储过程小工具(三)
- 【OpenCV/C++】KNN算法识别数字的实现原理与代码详解
- python教材答案字典与集合_Python——集合与字典练习
- linux sys伪用户作用,linux用户管理详解
- 把string时间取出月份_农村集市上现杀活蚌取出来的珍珠,是真的吗?为何价格这么便宜?...
- 时间字符串转时间戳_Python3日期与时间戳转换的几种方法
- OpenCV-Python实战(10)——详解 OpenCV 轮廓检测