用STL做会很方便

SET:

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
using namespace std;
const int mxn=;
int a[mxn];
int n,T;
int main(){
scanf("%d",&T);
int i,j;
while(T--){
scanf("%d",&n);
for(i=;i<=n;i++)scanf("%d",&a[i]);
set<int>s;
int L=,R=;
int 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 ;
}

MAP:

 /*by SilverN*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
const int mxn=;
int a[mxn];
int last[mxn];
map<int,int>cur;
int T,n;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int i,j;
cur.clear();
for(i=;i<=n;i++){
scanf("%d",&a[i]);
//预处理
if(!cur.count(a[i]))last[i]=-;
else last[i]=cur[a[i]];
cur[a[i]]=i;
}
int L=,R=;
int ans=;
while(R<=n){
while(R<=n && last[R]<L)R++;
ans=max(ans,R-L);
L++;
}
printf("%d\n",ans);
}
return ;
}

UVA 11527 Unique Snowflakes的更多相关文章

  1. uva 11572 unique snowflakes——yhx

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

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

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

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

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

  4. UVA - 11572 Unique Snowflakes

    /* STLsort离散化==T 手工sort离散化==T map在线==T map离线处理c==A 240ms */ #include<cstdio> #include<map&g ...

  5. uva 11572 - Unique Snowflakes(和书略有不同)

    本书是关于使用刘汝佳set, 通过收集找到.count()和删除.erase().这种方法比我好.用较短的时间. 我想map这个任务可以完成.但是,这是不容易删除,必须先找到find()标.然后删除索 ...

  6. UVA 11572 Unique snowflakes (滑窗)

    用set,保存当前区间出现过的数字,如果下一个数字没有出现过,加入,否则删掉左端点,直到没有重复为止 #include<bits/stdc++.h> using namespace std ...

  7. UVA - 11572 Unique Snowflakes 滑动扫描

    题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除 ...

  8. UVA - 11572 Unique Snowflakes(唯一的雪花)(滑动窗口)

    题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r] ...

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

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

随机推荐

  1. Studio 从入门到精通 (一)

    目标:Android Studio新手–>下载安装配置–>零基础入门–>基本使用–>调试技能–>构建项目基础–>使用AS应对常规应用开发 AS简介 经过2年时间的研 ...

  2. jq 操作table

    转载于:http://www.jb51.net/article/34633.htm jquery获取table中的某行全部td的内容方法,需要的朋友可以参考一下   <table>< ...

  3. js轮询

    业务场景为5秒ajax方式请求服务端更新状态,setInterval带参数模式. var objTimer = null; //创建 objTimer=setInterval(function(){l ...

  4. 普通请求和ajax请求的区别

    普通请求和ajax请求的区别? 下面的action返回一个json文件,文件内容为sts.*,data1

  5. 【转】【C#】SendMessage

    SendMessage是一个在user32.dll中声明的API函数,在C#中导入如下: using System.Runtime.InteropServices; [DllImport(" ...

  6. Apache Thrift

    Baidu Thrift  Google Thrift Apache Thrift - 可伸缩的跨语言服务开发框架

  7. Linux 网络编程八(epoll应用--大并发处理)

    //头文件 pub.h #ifndef _vsucess #define _vsucess #ifdef __cplusplus extern "C" { #endif //服务器 ...

  8. C语言 函数理解(以数组做参数)

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int run(int *p){ // ...

  9. 未能加载文件或程序集“XXXXX”或它的某一个依赖项。试图加载格式不正确的程序。

    未能加载文件或程序集“FastColoredTextBox, Version=2.10.5.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项.试图加载 ...

  10. “插件(application/x-vlc-plugin)不受支持”NPAPI和PPAPI的问题

    “插件(application/x-vlc-plugin)不受支持”NPAPI和PPAPI的问题 最近做一个前端的项目,项目需要引用VLC浏览器插件,javascript在IE.Firefox等浏览器 ...