输入一个长度为n n<=10 6  的序列A  找到一个尽量长的连续子序列  使得该序列中没有相同的元素

用滑动窗口法   时间复杂度n  好神奇

此题非常经典

map   410ms

#include<bits/stdc++.h>
using namespace std;
#define N 100000000
long a[N];
int main()
{
int cas;
cin>>cas;
while(cas--)
{
int n;cin>>n;
for(int i=;i<=n;i++)
scanf("%ld",&a[i]);
map<long,int>mp;
mp.clear();
int maxx=;
int j=;
for(int i=;i<=n;i++)
{
int ok=;
while(ok&&j<=n)
{
ok=;
if(!mp[ a[j] ])
{
maxx=max(maxx,j-i+);
mp[ a[j] ]++;
ok=;
}
j++;
}
j--;
mp[ a[i] ]--;
}
printf("%d\n",maxx);
}
}

LRJ 的代码只用240!。。诶

注意set的erase用法

#include<bits/stdc++.h>
using namespace std;
#define N 100000000
int a[N];
int main()
{
int cas;cin>>cas;
while(cas--)
{
int n;cin>>n;
for(int 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);
}
}

8-7 Unique Snowflakes UVA11572的更多相关文章

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

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

  2. Unique Snowflakes(窗口滑动)

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

  3. uva 11572 unique snowflakes——yhx

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

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

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

  5. UVA 11527 Unique Snowflakes

    用STL做会很方便 SET: /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring ...

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

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

  7. UVa 11572 (滑动窗口) Unique Snowflakes

    滑动窗口挺有意思的,如果符合条件右端点一直向前走,不符合的话,左端点向前走. #include <bits/stdc++.h> using namespace std; set<in ...

  8. UVA - 11572 Unique Snowflakes

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

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

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

随机推荐

  1. Dubbo学习笔记2:Dubbo服务提供端与消费端应用的搭建

    Demo结构介绍 Demo使用Maven聚合功能,里面有三个模块,目录如下: 其中Consumer模块为服务消费者,里面TestConsumer和consumer.xml组成了基于Spring配置方式 ...

  2. 为了拿Ph.D而做出的诺贝尔奖

  3. spring boot使用自定义配置的线程池执行Async异步任务

    一.增加配置属性类 package com.chhliu.springboot.async.configuration; import org.springframework.boot.context ...

  4. 你都掌握了吗?jQuery 选择器大全

    在 Dom 编程中我们只能使用有限的函数根据 id 或者 TagName 获取 Dom 对象. 然而在 jQuery 中则完全不同,jQuery 提供了异常强大的选择器用来帮助我们获取页面上的对象, ...

  5. No known class method for selector 'setImage:andName:'错误分析.//删除.h与.m文件时的注意事项

    CHENYILONG Blog No known class method for selector 'setImage:andName:'错误分析.//删除.h与.m文件时的注意事项         ...

  6. input必填

    <li> <span>出生日期</span> <div style="margin-left: 1.5rem;"> <inpu ...

  7. git 配置 SSH密钥

    1.登录用户 $ git config --global user.name "geekfeier" $ git config --global user.email " ...

  8. erp前端项目总结

    目录 一.项目目录(vue-cli2) 二.开发实践 (一) 权限 (二) 各组件间传递数据 (四) 路由 (七) 组织部门业务员三级联动 (八) 优化性能,手动绑定下拉框数据 (九) 验证 (十) ...

  9. 2016.6.17——Remove Duplicates from Sorted Array

    Remove Duplicates from Sorted Array 本题收获: 1.“删除”数组中元素 2.数组输出 题目: Given a sorted array, remove the du ...

  10. 关于注入抽象类报could not autowire field的问题

    昨天工作中遇到了一个很奇葩的问题,之前一直都没考虑过抽象类这块,一直用的注入接口实现类: 先看下错误: 因为在类中注入了一个抽象类,之前只有一个继承子类,所以没问题,这里要说一下抽象类的实例化: 抽象 ...