UVA11572-Unique Snowflakes-(最长不同连续子序列)
题意:给n个数,求最长不同连续子序列。n<=1e6。
解题过程:
1.记录数据存于数组
2.用左右指针l和r指向这段连续区间
3.右指针往右走,如果遇到没有存在于set集合的数就插入集合
否则左指针往右走,逐渐删去set里的数据,不断更新答案,一直保留最大值。
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<set>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;
#define ll long long int a[]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,l,r,maxx;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
set<int>se;
l=r=maxx=;
while(r<n)
{
while(r<n && !se.count( a[r] ) )///r<n也需要,否则可能r自增加过头了
se.insert(a[r++]);
maxx=max(maxx,r-l);///r目前是冒过头一位的,不需要r-l+1
se.erase(a[l++]);
}
printf("%d\n",maxx);
}
return ;
}
UVA11572-Unique Snowflakes-(最长不同连续子序列)的更多相关文章
- lintcode 最长上升连续子序列 II(二维最长上升连续序列)
题目链接:http://www.lintcode.com/zh-cn/problem/longest-increasing-continuous-subsequence-ii/ 最长上升连续子序列 I ...
- lintcode :最长上升连续子序列
题目: 最长上升连续子序列 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到右的序列.) 样例 ...
- lintcode-397-最长上升连续子序列
397-最长上升连续子序列 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到右的序列.) 注意事 ...
- lintcode_397_最长上升连续子序列
最长上升连续子序列 描述 笔记 数据 评测 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到 ...
- BNUOJ 4215 最长公共连续子序列
最长公共连续子序列 Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class ...
- 8-7 Unique Snowflakes UVA11572
输入一个长度为n n<=10 6 的序列A 找到一个尽量长的连续子序列 使得该序列中没有相同的元素 用滑动窗口法 时间复杂度n 好神奇 此题非常经典 map 410ms #inc ...
- 【TOJ 5065】最长连续子序列(前缀和)
Description 给定一系列非负整数,求最长的连续子序列,使其和是7的倍数. Input 第一行为正整数N(1<=N<=50000),接下来有N行,每行有一个非负整数,所有整数不大于 ...
- TOJ 5065: 最长连续子序列
5065: 最长连续子序列 Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByteTotal Submit: 140 ...
- UVA - 11572 Unique Snowflakes(唯一的雪花)(滑动窗口)
题意:输入一个长度为n(n <= 10^6)的序列A,找到一个尽量长的连续子序列AL~AR,使得该序列中没有相同的元素. 分析: 法一:从r=0开始不断增加r,当a[r+1]在子序列a[l~r] ...
随机推荐
- 「2017 山东一轮集训 Day4」棋盘(费用流)
棋盘模型 + 动态加边 #include<cstdio> #include<algorithm> #include<iostream> #include<cs ...
- php添加多组数据到数据库
//添加sql的数据 $sqldatas=getParam('sqldatas');//这里的sqldatas是从前台传过来的json字符串 //将json字符串转为json对象 $sqldata=j ...
- 爬虫概念 requests模块
requests模块 - 基于如下5点展开requests模块的学习 什么是requests模块 requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能 ...
- POJ2311 Cutting Game 博弈 SG函数
Cutting Game Description Urej loves to play various types of dull games. He usually asks other peopl ...
- 聊聊 cursor鼠标样式
在前端开发中,很多时候需要对页面的某些元素做鼠标样式的处理,比如button一般用pointer , 文本区一般用text......等等. 今天咱就来聊聊 这个经常用到的 cursor 属性 cur ...
- Fiddler设置抓取https请求
环境准备 1.安装最新版本的Fiddler程序 官网地址:https://www.telerik.com/fiddler 本文写的时候,fiddler最新的版本为5.0 2.安装fiddler证书生成 ...
- 安装hyperledger fabric V1.0.1
安装文档位置: https://github.com/hyperledger/fabric fabric代码托管地址 https://hyperledger-fabric.readthedoc ...
- activiti explorer5.22.0源代码解读
请求通过ExplorerApplicationServlet(AbstractApplicationServlet.service()方法)进入web系统中. Activiti Explorer的应用 ...
- IntelliJ IDEA 编译代码报错 找不到符号 符号: 找不到符号包 包
在使用IDEA的时候,经常出现过找不到包或者找不到符号的情况,可以尝试以下几种方式来解决 1.如果项目使用的是Maven可以使用Maven-Reimport 2.还可以 Invalidate and ...
- Your password has expired. To log in you must change it using a client that supports expired passwords.
[Lk] ERROR [11-26 23:01:51] [main] net.jweb.listener.AppInitializerListener.contextInitialized(231) ...