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

 #include <bits/stdc++.h>
using namespace std; set<int> Set; const int maxn = + ;
int a[maxn]; int Scan() { //输入外挂
int res = ;
char ch;
while((ch = getchar()) >= '' && ch <= '')
res = res * + (ch - '');
return res;
} int main()
{
//freopen("in.txt", "r", stdin);
int T, n;
scanf("%d", &T);
while(T--)
{
Set.clear();
scanf("%d", &n); getchar();
for(int i = ; i < n; ++i) a[i] = Scan();
int L = , R = , ans = ;
for(; L < n; ++L)
{
while(R < n &&!Set.count(a[R])) { Set.insert(a[R]); R++; }
ans = max(ans, R - L);
if(R == n) break;
Set.erase(a[L]);
}
printf("%d\n", ans);
} return ;
}

代码君

UVa 11572 (滑动窗口) Unique Snowflakes的更多相关文章

  1. UVa 12174 (滑动窗口) Shuffle

    首先预处理一下以每个数为结尾的前s个数是否能构成一个1~s的排列. 可以用cnt数组来记录每个数出现的次数和用一个变量记录一共有多少个不同的数出现. 然后枚举每种可能的情况,也就是枚举第一首歌会出现的 ...

  2. UVa 11572 Unique snowflakes【滑动窗口】

    题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostr ...

  3. (白书训练计划)UVa 11572 Unique Snowflakes(窗体滑动法)

    题目地址:UVa 11572 这样的方法曾经接触过,定义两个指针,不断从左向右滑动,推断指针内的是否符合要求. 这个题为了能高速推断是否有这个数,能够用STL中的set. 代码例如以下: #inclu ...

  4. Unique Snowflakes(窗口滑动)

    题目: Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devis ...

  5. uva 11572 unique snowflakes——yhx

    Emily the entrepreneur has a cool business idea: packaging and selling snowakes. She has devised ama ...

  6. 11572 - Unique Snowflakes(贪心,两指针滑动保存子段最大长度)

    Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...

  7. Unique Snowflakes UVA - 11572 (离散化+尺取法)

    Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...

  8. 紫书 例题8-7 UVa 11572(滑动窗口)

    滑动窗口这个方法名字非常形象, 先是窗口的右指针尽量往右滑, 滑不动了就滑窗口的左指针, 滑到右指针又可以开始滑动为止. 这道题是要记录滑的过程中最大的窗口长度, 限制条件是窗口中不能出现重复的值. ...

  9. uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...

随机推荐

  1. Delphi Variant oleVariant

    The OleVariant type exists on both the Windows and Linux platforms. The main difference between Vari ...

  2. Demo学习: CustomException

    CustomException 捕获程序发生的异常. 1. 抛出各种异常 procedure TMainForm.UniButton1Click(Sender: TObject); begin PBy ...

  3. Linux多进行之fork

    #include <unistd.h> //定义该函数 #include <sys/types.h> //定义函数的返回类型pid_t /* 功能:复制进程 参数:无 返回值: ...

  4. The Black Hole of Numbers (strtoint+inttostr+sort)

    For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...

  5. Oracle “CONNECT BY” 使用

    Oracle “CONNECT BY” 使用 功能说明: 语法结构如下: [ START WITH condition ] CONNECT BY [ NOCYCLE ] condition 说明: 1 ...

  6. SVN备份教程(一)

    最近一段时间在项目中用到了SVN备份的相关内容,这里给大家做一个简单的教程,重点在于SVN备份环境的搭建过程中,大家学到的解决问题的思维方式. 1.分类 SVN备份主要分为两种:一种是远程备份,另一种 ...

  7. 微软职位内部推荐-SDE

    微软近期Open的职位: Organization Summary:Engineering, Community & Online (ECO) is looking for a great & ...

  8. net use命令详细解释

    1)建立空连接: net use \\IP\ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立非空连接: net use \ ...

  9. linux驱动系列之文件压缩解压小节(转)

    转至网页:http://www.jb51.net/LINUXjishu/43356.html Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通 ...

  10. poj 2226 Muddy Fields (转化成二分图的最小覆盖)

    http://poj.org/problem?id=2226 Muddy Fields Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...