POJ 3320 尺取法,Hash,map标记
1、POJ 3320
2、链接:http://poj.org/problem?id=3320
3、总结:尺取法,Hash,map标记
看书复习,p页书,一页有一个知识点,连续看求最少多少页看完所有知识点
必须说,STL够屌。。
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
const int N=;
int p,a[N];
map<int,int>n,x; int main()
{
while(~scanf("%d",&p))
{
for(int i=;i<=p;i++)
{
scanf("%d",&a[i]);
n[a[i]]++;
}
int s=n.size(); //记录总类别 int l=,r=,ans=INF;
while(true)
{
while((r<=p)&&(x.size()<s)){ //尺取法,要满足范围要求,否则右端点移动
x[a[r++]]++;
}
if(x.size()<s)break;
ans=min(ans,r-l);
x[a[l++]]--;
if(x[a[l-]]<=)x.erase(a[l-]); //关健点,在范围内这个类别数<=0,就删去 }
printf("%d\n",ans);
} return ;
}
POJ 3320 尺取法,Hash,map标记的更多相关文章
- POJ 3320 (尺取法+Hash)
题目链接: http://poj.org/problem?id=3320 题目大意:一本书有P页,每页有个知识点,知识点可以重复.问至少连续读几页,使得覆盖全部知识点. 解题思路: 知识点是有重复的, ...
- POJ 3320 尺取法(基础题)
Jessica's Reading Problem Description Jessica's a very lovely girl wooed by lots of boys. Recently s ...
- poj 3320(尺取法)
传送门:Problem 3320 参考资料: [1]:挑战程序设计竞赛 题意: 一本书有 P 页,每页都有个知识点a[i],知识点可能重复,求包含所有知识点的最少的页数. 题解: 相关说明: 设以a[ ...
- A - Jessica's Reading Problem POJ - 3320 尺取
A - Jessica's Reading Problem POJ - 3320 Jessica's a very lovely girl wooed by lots of boys. Recentl ...
- poj 2100(尺取法)
Graveyard Design Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 6107 Accepted: 1444 ...
- POJ 2566 尺取法(进阶题)
Bound Found Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4297 Accepted: 1351 Spe ...
- 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 ...
随机推荐
- VC++中字符串编码的转换
在以前VC++6.0中默认的字符集是多字节字符集(MBCS:Multi-Byte Character Set),而VS2005及以后默认的字符集是Unicode,这样导致以前在VC6.0中非常简单实用 ...
- HDU5781 ATM Mechine(DP 期望)
应该是machine 和POJ3783 Balls类型相似. 现在上界为i元,猜错次数最多为j时,开始猜测为k元,有两种情况: 1 猜中:(i - k + 1) * dp[i - k][j] 2 猜不 ...
- 来访统计的JS代码
<script language="JavaScript"> var caution = false function setCookie(name, value, e ...
- EF Core 1.0中使用Include的小技巧
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:由于EF Core暂时不支持Lazy Loading,所以利用Include来加载额外 ...
- [荐]jquery插件开发入门
http://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html $.fn.myPlugin = function() { //在这里面,this指 ...
- MongoDB学习(2)—Node.js与MongoDB的基本连接示例
前提 已经安装了node.js和MongoDB,本文使用的node.js是v0.12.0,MongoDB是3.0.0. 初始化数据 启动MongoDB服务,在test数据库中插入一条实例数据: db. ...
- 外键为','(逗号)拼接ID,连接查询外键表ID
select distinct pipeId=substring(a.PipeIn,b.number,charindex(',',a.PipeIn+',',b.number)-b.number) fr ...
- 2016北京网络赛 hihocoder 1391 Countries 树状数组
Countries 描述 There are two antagonistic countries, country A and country B. They are in a war, and ...
- Arduino101学习(一)——Windows下环境配置
一.Arduino IDE下载 要开发Arduino 101/Genuino 101,你需要先安装并配置好相应的开发环境.下载地址 http://www.arduino.cn/thread-5838- ...
- MySQL的批处理
MySQL默认是关闭批处理的,所以我们在默认状态下(批处理未打开)向数据库中存入10000条数据,核心代码如下: package cn.itcast.demo5; import java.sql.Co ...