尺取法拓展——POJ3320
2024-10-15 21:14:00
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int moder = 1e9 + ;
const int maxn = ; int a[maxn]; int main()
{
int P;
scanf("%d",&P);
for(int i=;i < P;i++)
scanf("%d",&a[i]); set<int>st;
for(int i=;i < P;i++)
st.insert(a[i]); int n = st.size(); int s=,t=,num=;
map<int,int>cnt;
int res = P+;
for(;;)
{
while(t < P && num < n)
{
if(cnt[a[t]] == )
{
num++;
}
cnt[a[t]]++;
t++;
}
if(num < n) break;
res = min(res,t-s);
if(--cnt[a[s++]] == )
{
num--;
}
}
printf("%d\n",res);
return ;
} /*5
1 8 8 8 1 */
map很好用,记住。
最新文章
- [BI项目记]-TFS Express备份和恢复
- js动态添加行
- ubuntu14.04 gedit显示GB2312中文编码
- LeetCode(43. Multiply Strings)
- testNG中同一个test节点上class的执行顺序
- shopnc 二次开发 每日签到积分领取
- jquery1.9+获取append后的动态元素
- http压力测试
- 最新 Arduino 驱动 12接口/户外 LED显示屏/LED点阵屏/LED单元板
- C# System.Attribute(验证类)
- [置顶] Android框架攻击之Fragment注入
- VS怎样创建和使用lib文件
- CSS3学习笔记(1)-CSS3选择器
- java中super关键字
- 魔术常量(Magic constants)
- centos 6.8 下安装redmine(缺陷跟踪系统)
- python3 第三十一章 - 模块
- SpringCloud服务注册与发现
- centos6.5上安装redis3.2.1遇见的坑
- CXF Spring开发WebService,基于SOAP和REST方式
热门文章
- c# BitArray 复制数组 copyto
- Celery和Rabbitmq自学
- vue知识总汇
- android(十五) FTP的两种工作模式
- SNMP 原理及配置简述 net-snmp-utils net-snmp 第2版基于SNMP 群体名(community name) 第3版引入了安全性更高的访问控制方法 SNMP协议操作只有4种 Apache的php_snmp 模块
- file /etc/httpd/conf.d/php.conf from install of php-5.6.37-1.el7.remi.x86_64 conflicts with file from package mod_php71w-7.1.18-1.w7.x86_64
- 528. Random Pick with Weight
- Java 泛型通配符上限和通配符下限
- url的正则表达式
- 20145311实验四 ";Android开发基础";