博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 11572 (滑动窗口) Unique Snowflakes
阅读量:4589 次
发布时间:2019-06-09

本文共 973 字,大约阅读时间需要 3 分钟。

滑动窗口挺有意思的,如果符合条件右端点一直向前走,不符合的话,左端点向前走。

1 #include 
2 using namespace std; 3 4 set
Set; 5 6 const int maxn = 1000000 + 10; 7 int a[maxn]; 8 9 int Scan() { //输入外挂10 int res = 0;11 char ch;12 while((ch = getchar()) >= '0' && ch <= '9')13 res = res * 10 + (ch - '0');14 return res;15 }16 17 int main()18 {19 //freopen("in.txt", "r", stdin);20 int T, n;21 scanf("%d", &T);22 while(T--)23 {24 Set.clear();25 scanf("%d", &n); getchar();26 for(int i = 0; i < n; ++i) a[i] = Scan();27 int L = 0, R = 0, ans = 0;28 for(; L < n; ++L)29 {30 while(R < n &&!Set.count(a[R])) { Set.insert(a[R]); R++; }31 ans = max(ans, R - L);32 if(R == n) break;33 Set.erase(a[L]);34 }35 printf("%d\n", ans);36 }37 38 return 0;39 }
代码君

 

转载于:https://www.cnblogs.com/AOQNRMGYXLMV/p/4278155.html

你可能感兴趣的文章
对类使用dir()
查看>>
【13】淘宝sdk——入门实战之header.php制作(一)
查看>>
安装SoapUI Pro
查看>>
杜教BM模板
查看>>
Makefile经典教程(掌握这些足够)
查看>>
自己成功的编写的将数据从excel导入到access中
查看>>
【Leetcode】【Easy】Compare Version Numbers
查看>>
014 链表中倒数第k个结点
查看>>
Python的pip安装Django
查看>>
第一冲刺阶段——站立会议第二天4月19日
查看>>
hdu-----(2807)The Shortest Path(矩阵+Floyd)
查看>>
简洁的MysqlHelper
查看>>
Android面试收集录2 Broadcast Receiver详解
查看>>
基于HTML5实现的中国象棋游戏
查看>>
Luogu P2024 [NOI2001]食物链 | 并查集
查看>>
openLayers3 中实现多个Overlay
查看>>
SQlServer2008 之 定时执行sql语句作业的制定
查看>>
函数式编程
查看>>
由浅入深之Jquery笔记(1)
查看>>
IE、FF、Chrome浏览器中的JS差异介绍
查看>>