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

【题意】

题意

【题解】

设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 here
new 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());
}
}
}

【Codeforces 977F】Consecutive Subsequence的更多相关文章

  1. 【Codeforces 632D】 Longest Subsequence

    [题目链接] 点击打开链接 [算法] 设取的所有数都是k的约数,则这些数的lcm必然不大于k. 对于[1, m]中的每个数,统计a中有多少个数是它的约数即可. [代码] #include<bit ...

  2. 【29.41%】【codeforces 724D】Dense Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 750E】New Year and Old Subsequence

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【33.10%】【codeforces 604C】Alternative Thinking

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【38.02%】【codeforces 625B】War of the Corporations

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

随机推荐

  1. 盘点国内网站常用的一些 CDN 公共库加速服务(转载)

    百度CND jQuery 地址:<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></scri ...

  2. js中return的作用及用法

    这里面的return含有一些细节知识: 例如:onClick='return add_onclick()'与 onClick='add_onclick()'的区别 JAVASCRIPT在事件中调用函数 ...

  3. linux学习之路7 linux下获取帮助

    help 帮助 ls -h或者ls - -help man 最常用的帮助命令 man (+数字 )+命令 (数字代表文档帮助类型) man -k 关键字 可以用来查询包含该关键字的文档 info 与m ...

  4. 382 Linked List Random Node 链表随机节点

    给定一个单链表,随机选择链表的一个节点,并返回相应的节点值.保证每个节点被选的概率一样.进阶:如果链表十分大且长度未知,如何解决这个问题?你能否使用常数级空间复杂度实现?示例:// 初始化一个单链表 ...

  5. Modbus通讯错误检测方法

    标准的Modbus串行网络采用两种错误检测方法.奇偶校验对每个字符都可用,帧检测(LRC和CRC)应用于整个消息.它们都是在消息发送前由主设备产生的,从设备在接收过程中检测每个字符和整个消息帧. 用户 ...

  6. .Net实战之反射外卖计费

    场景 叫外卖支付,可以有以下优惠: 1.  满30元减12 2.  是会员减配送费,比如5元 3.  优惠券 …. 问题? 如何在不改代码的情况下更灵活的去控制优惠的变化??? 有些代码与实际业务可能 ...

  7. from scipy import spatial 出现 from .qhull import * ImportError: DLL load failed: The specified module could not be found. 错误

    错误描述: 本人机器window8.1 64位,python2.7. Traceback (most recent call last): File "C:/Users/Hamid/Docu ...

  8. 观察者模式在Foundation框架通知中的应用

    GitHub传送门 1.何为观察者模式? 观察者设计模式定义了对象间的一种一对多的依赖关系,以便一个对象的状态发生变化时,所有依赖于它的对象都得到通知并自动刷新. 举个简单的例子:你和你的舍友都订阅了 ...

  9. ThinkPHP---thinkphp会话支持和文件载入

    [一]会话控制 会话支持一般指cookie和session,在ThinkPHP里为了方便开发,封装了cookie和session方法. (1)session方法 在函数库封装了session方法 se ...

  10. 使用cloudcompare进行对比轨迹及评价

    0.预备知识: 我的系统是Ubuntu 16.04. 在其他发行版中,可能需要先安装snap(如有必要,请参阅相应的文档).快照发布在3个频道:“稳定”,“测试版”和“边缘”.“稳定版”和“测试版”频 ...