8-7 Unique Snowflakes UVA11572
输入一个长度为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的更多相关文章
- Unique Snowflakes UVA - 11572 (离散化+尺取法)
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...
- Unique Snowflakes(窗口滑动)
题目: Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devis ...
- uva 11572 unique snowflakes——yhx
Emily the entrepreneur has a cool business idea: packaging and selling snowakes. She has devised ama ...
- 11572 - Unique Snowflakes(贪心,两指针滑动保存子段最大长度)
Emily the entrepreneur has a cool business idea: packaging and selling snowflakes. She has devised a ...
- UVA 11527 Unique Snowflakes
用STL做会很方便 SET: /*by SilverN*/ #include<iostream> #include<algorithm> #include<cstring ...
- UVa 11572 Unique snowflakes【滑动窗口】
题意:给出 n个数,找到尽量长的一个序列,使得该序列中没有重复的元素 看的紫书,滑动窗口来做的 当右端碰到有相同的数的时候,左端向前滑动一个数 模拟一个样例好理解些 #include<iostr ...
- UVa 11572 (滑动窗口) Unique Snowflakes
滑动窗口挺有意思的,如果符合条件右端点一直向前走,不符合的话,左端点向前走. #include <bits/stdc++.h> using namespace std; set<in ...
- 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()标.然后删除索 ...
随机推荐
- H5页面中唤起native app
现在各类app,分享出去的H5页面中,一般都会带着一个立即打开的按钮,如果本地安装了app,那么就直接唤起本地的app,如果没有安装,则跳转到下载.这是一个很正常的推广和导流量的策略,最近产品经理就提 ...
- [NOI1997] 积木游戏
COGS 261. [NOI1997] 积木游戏 http://www.cogs.pro/cogs/problem/problem.php?pid=261 ★★ 输入文件:buildinggame ...
- Python学习笔记4-os,sys模块
一.os模块 import os print(os.getcwd())#取当前工作目录 os.chmod("/usr/local",7)#给文件/目录加权限 print(os.ch ...
- javascript里你绝对用的上的字符分割函数--原创
// 在数组内字符为未知情况下,合并和分割的解决方案 var data = [['your name', 'myvalue'], ['myr name', 'thivalue']]; function ...
- soj2013.Pay Back
2013. Pay Back Constraints Time Limit: 1 secs, Memory Limit: 256 MB Description "Never a borrow ...
- JHipster项目启动后默认的8080主页是空白页面?
1.背景 根据官网一步步地生成项目,他喵的启动后居然是一个空白页面,这怎么玩啊?还有这种操作的吗?跟说好的不一样啊!关于JHipster资料,国内少的可怜,几乎都是同一样的东西,纯介绍的文章,只好上s ...
- 16、DecimalFormat类
DecimalFormat类概述 在一些金融或者银行的业务里面,会出现这样千分位格式的数字,¥123,456.00,表示人民币壹拾贰万叁仟肆佰伍拾陆元整,java.text包下提供了一个Decimal ...
- Python练习-基于授权方式包装list之与根儿哥必有一战
# 编辑者:闫龙 # 基于授权定制自己的列表类型,要求定制的自己的__init__方法, # 定制自己的append:只能向列表加入字符串类型的值 # 定制显示列表中间那个值的属性(提示:proper ...
- Python练习-迭代器-模拟cat|grep文件
代码如下: # 编辑者:闫龙 def grep(FindWhat): f=open("a.txt","r",encoding="utf8") ...
- 收集了一些python的文章
来自: 戴铭 2010-08-31 17:52:31 newthreading - safer concurrency for Python 安全并发(1回应) http://www.starming ...