题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素

看的紫书,滑动窗口来做的

当右端碰到有相同的数的时候,左端向前滑动一个数

模拟一个样例好理解些

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int maxn=+;
int a[maxn]; int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",&a[i]); set<int> s;
int l=,r=,ans=;
while(r<n){
while(r<n&&!s.count(a[r])) s.insert(a[r++]);
ans=max(ans,r-l);
s.erase(a[l++]);
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. jquery:closest和parents的主要区别
  2. pacman -Syu : key could not be looked up remotely.
  3. thinkphp- 许愿墙-1
  4. Call and Apply in JavaScript
  5. Chrome浏览器跨域问题
  6. 解决md5不是windows平台FIPS验证的加密算法的一部分的怪异问题
  7. SSM-SpringMVC-05:SpringMVC视图解析器InternalResourceViewResolver配置
  8. 关于px,分辨率,ppi的辨析
  9. HTML5移动端拖动惯性
  10. 【Spring】11、Spring事务管理
  11. android recovery代码修改之原生建议
  12. 虚拟机连不上网 Xshell连不上虚拟机
  13. jquery实现拖拽进度条并显示百分比的特效
  14. mysql不存在插入否则更新
  15. 使用python实现人脸检测&lt;转载&gt;
  16. swift和oc的protocol的成员变量
  17. 附4 springboot源码解析-run()
  18. Ubuntu下解决apt update时签名无效问题
  19. Error:Annotation processors must be explicitly declared now.
  20. asp.net core 错误定位 &amp; vs2017 远程调试部署在centos上的asp.net core程序

热门文章

  1. Feature Extraction
  2. VMware ESXi虚拟机克隆及迁移
  3. Eclipse 创建Maven工程
  4. 【BZOJ】【3398】【USACO 2009 Feb】Bullcow 牡牛和牝牛
  5. ZOJ Monthly, August 2014
  6. [转载]JS中如何定义全局变量
  7. asp.net 获取客户机IP地址
  8. java调用dll文件中的类型转换
  9. [C++]默认构造函数
  10. 如何防止通过IP地址访问Tomcat管理页面