【链接】 我是链接,点我呀:)
【题意】

题意

【题解】

设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度。
用f[i]和f[i-1]+1来转移即可

【代码】

import java.io.*;
import java.util.*;public class Main {static InputReader in;static PrintWriter out;public static void main(String[] args) throws IOException{//InputStream ins = new FileInputStream("E:\\rush.txt");InputStream ins = System.in;in = new InputReader(ins);out = new PrintWriter(System.out);//code start from herenew Task().solve(in, out);out.close();}static int N = (int)2e5;static class Task{int n;HashMap<Integer,Integer> dic = new HashMap<Integer,Integer>();int a[] = new int[N+10];ArrayList<Integer> v = new ArrayList<Integer>();public void solve(InputReader in,PrintWriter out) {n = in.nextInt();int len = 0,idx = -1;for (int i = 1;i <= n;i++) {a[i] = in.nextInt();int x = a[i];if (dic.containsKey(x)) {int cur = dic.get(x);int temp = 0;if (dic.containsKey(x-1)) {temp = dic.get(x-1);}cur = Math.max(cur, temp+1);dic.put(x, cur);}else {int temp = 0;if (dic.containsKey(x-1)) {temp = dic.get(x-1);}dic.put(x, temp+1);}int temp0 = dic.get(x);if (temp0>len) {len = temp0;idx = i;}}out.println(len);int now = a[idx];for (int i = idx;i >= 1;i--) {if (a[i]==now) {v.add(i);now--;}}for (int i = (int)v.size()-1;i >= 0;i--) {out.print(v.get(i)+" ");}}}static class InputReader{public BufferedReader br;public StringTokenizer tokenizer;public InputReader(InputStream ins) {br = new BufferedReader(new InputStreamReader(ins));tokenizer = null;}public String next(){while (tokenizer==null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(br.readLine());}catch(IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}}
}

转载于:https://www.cnblogs.com/AWCXV/p/10575485.html

【Codeforces 977F】Consecutive Subsequence相关推荐

  1. 【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 ...

  2. 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

    题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...

  3. 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)

    题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...

  4. 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)

    题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...

  5. 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)

    题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...

  6. 【CodeForces 997C】Sky Full of Stars(组合计数)

    题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...

  7. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  8. 【codeforces 508B】Anton and currency you all know

    [题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...

  9. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  10. 【codeforces 807C】Success Rate

    [题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...

最新文章

  1. LeetCode简单题之只出现一次的数字
  2. 静态库调用_静态链接和动态链接对比简析
  3. ITK:将颜色图应用于标签图并将其叠加在图像上
  4. @ResponseBody,@RequestBody,@PathVariable
  5. [C# 基础知识系列]专题六:泛型基础篇——为什么引入泛型
  6. 微信小程序+微信公众号开发总结
  7. mysql集群初始化配置_集群Cluster MySQL的安装配置和使用
  8. python 里什么时候缩进_python什么时候缩进
  9. 【课题总结】OpenCV 抠图项目实战(1)目录摘要
  10. [bzoj1355][Baltic2009]Radio Transmission_KMP
  11. Facebook的智能音箱跳,票,了
  12. Access2007数据库下载地址与AccessHelper
  13. 系统架构设计师考试大纲 考点
  14. 单片机74LS164C语言例子,51单片机控制74LS164芯片输出64位的数组
  15. 基于嵌入式Linux的MP3播放器的设计与实现
  16. 五子棋对弈(Socket--【服务器】--联机)
  17. 【量化选基】每年初买入近5年 收益率最高的10支基金会暴富吗?
  18. 针对瑞萨单片机编译时空间无法全部使用问题的解决方案
  19. ARM Cortex-M3
  20. Ubuntu安装Matlab其Simulink没有菜单栏的解决方案(转载可用)

热门文章

  1. 关于HTTP请求报文和响应报文学习笔记
  2. 前端面试题之手写事件模型及事件代理/委托
  3. Week 2 代码审查
  4. 微软面试4、在二元树中找出和为某一值的所有路径
  5. 【领域综述】NLP领域,你推荐哪些综述性的文章?
  6. 【面经】深度学习算法岗(京东)
  7. NLP硬核入门-Seq2Seq和Attention机制
  8. 【ACL2019】文本摘要研究工作总结
  9. 6.1 API : AdaBoostClassifier与AdaBoostRegressor
  10. pytorch GPU分布式训练 数据并行