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