D - Unique Snowflakes
程序员文章站
2022-03-12 16:56:33
...
题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素
这里给出思路:
给出代码:
#include <iostream>
#include <set>
#include <cstdio>
#include <map>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn=1000000+5;
int arr[maxn];
int main(){
int time;
cin>>time;
while(time--){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
set<int> slide;
set<int>:: iterator it;
int left=1,right=1;
int ans=0;
while(right<=n){
while(right<=n&&!slide.count(arr[right])){
slide.insert(arr[right]);
right++;
}
ans=max(right-left,ans);
while(left<=right&&left<=n&&slide.count(arr[right])){
slide.erase(arr[left]);
left++;
}
// slide.erase(arr[left]);
// left++;
}
cout<<ans<<endl;
}
}
上一篇: String Compression
下一篇: HTTP compression
推荐阅读
-
java8中使用java.util.Base64报“java.lang.IllegalArgumentException: Illegal base64 character d”
-
Box2d 物理引擎
-
Fatal error: Call to undefined function: iconv() in d:wwwPiaokouwwwrootpiaok解决方案
-
Codeforces Round #251 (Div. 2)-C,D_html/css_WEB-ITnose
-
为啥printf ("(9.95 * 100) = %d n", (9.95 * 100));结果是994?
-
Failed to load keystore type JKS with path tomcat.keystore due to D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tm
-
Failed to load keystore type JKS with path tomcat.keystore due to D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tm
-
codeforces 977D(DFS)
-
Cocos2d-x 3.0心得(04)
-
Android版3D-Touch Shortcuts实现类似支付宝桌面快捷配置