Consecutive Subsequence
边循环边输入,用map记录,当前长度等于上一个的长度加一。记录最后一个和最大长度。先输出长度,在输出连续的序号。
代码:
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<int,int> sum;
int a[2000005];
int main(){
int n,x,maxl=0,last=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>x;
a[i]=x;
sum[x]=sum[x-1]+1;//前面一个的最大长度+1
int t=sum[x];
if(t>maxl){
maxl=sum[x];//记录长度和最后一个
last=x;
}
}
cout<<maxl<<endl;
int num=last-maxl+1;//第一个
for(int i=1;i<=n;i++){
if(a[i]==num){
cout<<i<<" ";
num++;//序号+1,继续找号码
}
}
return 0;
}
Consecutive Subsequence相关推荐
- 【Codeforces - 977F】Consecutive Subsequence(STLmap,输出路径,dp)
题干: You are given an integer array of length nn. You have to choose some subsequence of this array o ...
- cf----2019-10-20(Consecutive Subsequence,Almost Arithmetic Progression,Mentors)
一场游戏一场空,最终 最初都由我掌控,好像一身从容,不曾有狼狈伤痛,可深夜一个人该如何相拥? You are given an integer array of length nn. You have ...
- Codeforces Round #479 (Div. 3)【完结】
2022.2.28 开始复盘div3 题目链接:https://codeforces.com/contest/977 目录 A. Wrong Subtraction[签到模拟题] B. Two-gra ...
- 【测试点分析】1104 Sum of Number Segments (20 分)
立志用更少的代码做更高效的表达 Given a sequence of positive numbers, a segment is defined to be a consecutive subse ...
- Vasya and String CodeForces - 676C(尺取法)
High school student Vasya got a string of length n as a birthday present. This string consists of le ...
- Continuous Intervals Gym - 102222L(2018宁夏邀请赛暨2019银川icpc网络预选赛)
Lamis is a smart girl. She is interested in problems about sequences and their intervals. Here she s ...
- biodist r语言_R语言 Biostrings包 pairwiseAlignment()函数中文帮助文档(中英文对照)
pairwiseAlignment(Biostrings) pairwiseAlignment()所属R语言包:Biostrings Optimal Pairwise Alignment 最佳成对排列 ...
- 【后缀数组】【线段树】codeforces102028H Can You Solve the Harder Problem?
H. Can You Solve the Harder Problem? time limit per test6.0 s memory limit per test1024 MB inputstan ...
- 百亿题典之C++编程题面试题
原文地址:百亿题典之C++编程题面试题作者:百亿题典 1. 在linked list中找倒数第N个结点 2. 倒转linked list 3. 二叉树的结点有指向parent的指针,求最近公共祖先 4 ...
最新文章
- 【牛腩新闻发布系统】开发前的准备01
- linux进程间通信:popen函数通过管道与shell通信
- 世界一流大学真的建成了?26所“985”高校自评报告出炉
- SQLite入门与分析(二)---设计与概念
- 深度松下MTS视频恢复软件 v8.1.0
- 算法笔记_面试题_19.链表_模板及示例十几道
- 使用python对学生表的查询_python + mysql 实现查询表数据
- 【深度学习笔记】(一)Octave
- 文章原创度检测神器:copyscape及duplichecker
- 阿里云服务器可以用来干什么?
- VMware Workstation Ubuntu 20.04 LTS无法连接网络问题
- java 计算百分数问题
- mPEG-Phosphate,甲氧基聚乙二醇磷酸盐,mPEG-PHOS
- 两名一流高校硕士同年毕业论文高度雷同惹争议,怎么过的查重?
- 「解决方案」Acrel-2000Z变电站综合自动化系统
- 【计算机网络】(一)走进网络
- 南宁城市建设发展市政工程人才需求暴涨
- 12 DB操作 Hibernate Panache
- Modbus转Profinet网关案例 | 三菱FR-A700系列变频器配置方法
- 模电总结二:基本运算电路