UVA 11527 Unique Snowflakes
用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的更多相关文章
- uva 11572 unique snowflakes——yhx
Emily the entrepreneur has a cool business idea: packaging and selling snowakes. She has devised ama ...
- (白书训练计划)UVa 11572 Unique Snowflakes(窗体滑动法)
题目地址:UVa 11572 这样的方法曾经接触过,定义两个指针,不断从左向右滑动,推断指针内的是否符合要求. 这个题为了能高速推断是否有这个数,能够用STL中的set. 代码例如以下: #inclu ...
- UVa 11572 Unique snowflakes【滑动窗口】
题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostr ...
- UVA - 11572 Unique Snowflakes
/* STLsort离散化==T 手工sort离散化==T map在线==T map离线处理c==A 240ms */ #include<cstdio> #include<map&g ...
- uva 11572 - Unique Snowflakes(和书略有不同)
本书是关于使用刘汝佳set, 通过收集找到.count()和删除.erase().这种方法比我好.用较短的时间. 我想map这个任务可以完成.但是,这是不容易删除,必须先找到find()标.然后删除索 ...
- UVA 11572 Unique snowflakes (滑窗)
用set,保存当前区间出现过的数字,如果下一个数字没有出现过,加入,否则删掉左端点,直到没有重复为止 #include<bits/stdc++.h> using namespace std ...
- UVA - 11572 Unique Snowflakes 滑动扫描
题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除 ...
- UVA - 11572 Unique Snowflakes(唯一的雪花)(滑动窗口)
题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r] ...
- Unique Snowflakes UVA - 11572 (离散化+尺取法)
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...
随机推荐
- 实例化Model的三种方式
- Linux系统批量化安装部署之Cobbler
说明: Cobbler服务器系统:CentOS 5.10 64位 IP地址:192.168.21.128 需要安装部署的Linux系统: eth0(第一块网卡,用于外网)IP地址段:192.168.2 ...
- 认识实验室信息管理系统(LIMS)
在当今互联网如日中天的大环境下,各种伴随着互联网的产物如p2p,o2o在如火如荼的进行着,吸引了大量的开发人员都涌向了这个行业,所有的技术似乎都在围绕着互联网发展,传统行业软件开发的人气和关注度就相形 ...
- FusionCharts V3图表导出图片和PDF属性说明(转)
百闻不如一见,狠狠点击,快快下载:(演示文档有错误,不提供下载了.待新的演示文档出来.) 许多朋友说上面的DEMO用不了.fusioncharts官方的演示非常不错,就是来不及整理,各位大侠们可以研究 ...
- 转载:有关SQL server connection Keep Alive 的FAQ(3)
转载:http://blogs.msdn.com/b/apgcdsd/archive/2012/06/07/sql-server-connection-keep-alive-faq-3.aspx 这个 ...
- 微软职位内部推荐-SW Engineer for Skype
微软近期Open的职位: We are the Skype Beijing team. Skype division drives the communications strategy for Mi ...
- 一些正则验证-JS
Validation = { textCount: function(field, counter, maxLimit) { var message = $(field).val(); if ($(f ...
- C语言 百炼成钢2
//题目4:输入某年某月某日,判断这一天是这一年的第几天? #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<st ...
- C#+OpenGL编程之再见小桃子(The Tao Framework)
本文基础: C#+OpenGL编程之OpenGL 纹理载入 C#+OpenGL编程之OpenGL 多重纹理 小桃子The Tao FrameworkTao提供的所有库都是完全开源的.其中的多数库都可以 ...
- matlab文件操作及读txt文件(fopen,fseek,fread,fclose)
文件操作是一种重要的输入输出方式,即从数据文件读取数据或将结果写入数据文件.MATLAB提供了一系列低层输入输出函数,专门用于文件操作. 1.文件的打开与关闭 1)打开文件 在读写文件之前,必须先用f ...