UVa 11572 唯一的雪花(优化策略)
2015-01-29 15:26
281 查看
题目描述:
输入一个长度为n(n<=1000000)的序列A, 找到一个尽量长的连续子序列A(L)-->A(R),是的该序列中没有相同的元素。
输入:
T:代表组数
n:代表有n个数
这一行输入n个数。。。。。。
输出:最长的没有重复元素的长度值。
样例输入:
1
8
1 2 3 2 5 6 7 9
样例输出:
6
输入一个长度为n(n<=1000000)的序列A, 找到一个尽量长的连续子序列A(L)-->A(R),是的该序列中没有相同的元素。
输入:
T:代表组数
n:代表有n个数
这一行输入n个数。。。。。。
输出:最长的没有重复元素的长度值。
样例输入:
1
8
1 2 3 2 5 6 7 9
样例输出:
6
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <string> #include <algorithm> #include <queue> #include <set> using namespace std; int a[1000005]; int main() { int t; int n; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d", &a[i] ); } set<int>s; int ll=0, rr=0, ans=0; while(rr<n) { while(rr<n && s.count(a[rr])==0 ) { s.insert(a[rr++]); } ans=max(ans, rr-ll ); s.erase(a[ll++]); } printf("%d\n", ans ); } return 0; }
相关文章推荐
- Cpp环境【Uva11572】【Vijos2788】唯一的雪花(并没有雪花=_=)
- 滑动窗口(唯一的雪花,uva 11572)
- Uva 11572 唯一的雪花
- [UVa 11572] 唯一的雪花(Unique Snowflakes)
- uva 11572 唯一的雪花 (滑动窗口)
- UVA - 11572 Unique Snowflakes(唯一的雪花) : 滑动窗口
- 唯一的雪花(Uva 11572)
- 例题8-7 唯一的雪花(Unique snowflakes, UVa 11572)
- 唯一的雪花(Unique snowflakes,UVa 11572)滑动窗口+set
- UVa 11572 唯一的雪花(滑动窗口)
- uva 11572 Unique Snowflakes (唯一的雪花)
- 【uva 11572】 唯一的雪花 滑动窗口
- uva 11572 唯一的雪花 Unique Snowflakes
- Android上的内存分配策略优化
- UVA1635 Irrelevant Elements —— 唯一分解定理 + 二项式定理
- Uva 11732 "strcmp()" Anyone? ——空间优化的字典树
- MysqlInnoDB优化策略
- Hibernate 性能优化策略和缓存详解
- 深入浅出JVM优化策略
- HBase 数据库检索性能优化策略