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 ...
随机推荐
- HTML5和css3的总结
简单的罗列一个HTML5的新东西,以后的几天里详细的过一遍一个挺有用的网站:www.css88.com [H5的新标签] 用之前的标签完全可以代替的:header footer aside atric ...
- 让input框只能输入数字
var oInput = document.querySelector("input");oInput.onkeyup = function () { var value = th ...
- Cobbler自动化批量安装linux服务器的操作记录
Cobbler为何物?Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows.该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命 ...
- UICollectionView移动
collectionView在iOS9中发布了一个可以移动cell的新特性,实现如下: 1.创建collectionView并设置代理 - (UICollectionView *)collection ...
- scroll滚动条插件初始化问题
一种特殊场景下是滚动条容器先隐藏,点击某个东西后显示出来.然后实例化滚动条.实例 js: var flag = true; document.getElementById('btn1').onclic ...
- Unity 协程Coroutine综合测试
using UnityEngine; using System.Collections; using System.Text; public class rotCube : MonoBehaviour ...
- C# 结构体
1,结构体不能出现在继承关系中,除了继承接口. 结构体不能继承类或结构,也不能被类或结构继承,只可以继承接口. 2,struct不能定义默认构造函数(无参构造函数),也不能定义析构函数.class对这 ...
- no.4 抽奖测试
#-*-coding=gbk-*- import sys import random a=[] try: for x in range(1,20+1,1): #打印20人数编号 a.append(x) ...
- Android 动画之AlphaAnimation应用详解
窗口的动画效果,淡入淡出什么的,有些游戏的欢迎动画,logo的淡入淡出效果就使用AlphaAnimation.AlphaAnimation(0.01f, 1.0f); 从0.01f到1.0f渐变.学过 ...
- css 兼容
color:#0000FF\9; ;/*ie6,ie7,ie8*/ *color:#FFFF00;/*ie7*/ _color:#FF0000;/*ie6*/ body:nth-of-type(1) ...