1570: Sequence Number

时间限制: 1 Sec  内存限制: 1280 MB

题目描述

In Linear algebra, we have learned the definition of inversion number:

Assuming A is a ordered set with n numbers ( n > 1 ) which are different from each other. If exist positive integers i , j, ( 1 ≤ i < j ≤ n and A[i] > A[j]), <A[i], A[j]> is regarded as one of A’s inversions. The number of inversions is regarded as inversion number. Such as, inversions of array <2,3,8,6,1> are <2,1>, <3,1>, <8,1>, <8,6>, <6,1>,and the inversion number is 5.

Similarly, we define a new notion —— sequence number, If exist positive integers i, j, ( 1 ≤ i ≤ j ≤ n and A[i]  <=  A[j], <A[i], A[j]> is regarded as one of A’s sequence pair. The number of sequence pairs is regarded as sequence number. Define j – i as the length of the sequence pair.

Now, we wonder that the largest length S of all sequence pairs for a given array A.

输入

There are multiply test cases.

In each case, the first line is a number N(1<=N<=50000 ), indicates the size of the array, the 2th ~n+1th line are one number per line, indicates the element Ai (1<=Ai<=10^9) of the array.

输出

Output the answer S in one line for each case.

样例输入

5
2 3 8 6 1

样例输出

3

解题思路

求出当A[i]<=A[j],i<=j时,j-i的最大长度。

#include <stdio.h>
#include <algorithm>
using namespace std;
int a[50010];
int main ()
{
    int n, i, j, k, maxn;
    while (~scanf("%d",&n))
    {
        for (i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for (i = n - 1; i >= 0 && a[i] < a[0]; i--);
        maxn = i;
        for (j = 1; j < n - maxn; j++)
        {
            for (k = n - 1; k >= j + maxn; k--)
            {
                if (a[j] <= a[k])
                {
                    maxn = max(maxn, k - j);
                    break;
                }
            }
        }
        printf("%d\n", maxn);
    }
    return 0;
}

Sequence Number的更多相关文章

  1. mysql oom之后的page 447 log sequence number 292344272 is in the future

    mysql oom之后,重启时发生130517 16:00:10 InnoDB: Error: page 447 log sequence number 292344272InnoDB: is in ...

  2. [crypto][ipsec] 简述ESP协议的sequence number机制

    预备 首先提及一个概念叫重放攻击,对应的机制叫做:anti-replay https://en.wikipedia.org/wiki/Anti-replay IPsec协议的anti-replay特性 ...

  3. 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...

  4. InnoDB: The log sequence number in ibdata files does not match

    InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...

  5. hzau 1205 Sequence Number(二分)

    G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...

  6. Thread <number> cannot allocate new log, sequence <number>浅析

    有时候,你会在ORACLE数据库的告警日志中发现"Thread <number> cannot allocate new log, sequence <number> ...

  7. ORA-02287: sequence number not allowed here问题的解决

    当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table ...

  8. [转] 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)

    点击阅读原译文 原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ ...

  9. pymysql.err.InternalError: Packet sequence number wrong - got 45 expected 0

    原因: 使用了多线程,多线程共享了同一个数据库连接,但每个execute前没有加上互斥锁 方法: 方法一:每个execute前加上互斥锁 lock.acquire()         cursor.e ...

随机推荐

  1. ionic编译安卓App

    安装node.js 安装Android Studio 运行Android Studio安装SDK,在D:\AndroidSDK 配置SDK环境 ANDROID_HOME=D:\AndroidSDK P ...

  2. linux 初识系统分区

  3. python - 练习统计随机字母数据

    # 随机字母,统计每个字母的数量: # 1.按a-z 的方式 显示每个字母的数量 # 2.按从多到少的方式 显示每个字母的数据 info= "fkdsfkasefhjsadfjagroekl ...

  4. Android Studio buildGrade文件注解

    apply plugin: 'com.android.application' //指定用的那个插件,android App插件打包得到.apk文件                     //com ...

  5. MySql cmd下的学习笔记 —— 有关建立数据库的操作(连接Mysql,建立数据库,删除数据库等等)

    (01) 连接数据库 mysql -uroot -p 之后输入密码 ******.(由于我的密码设置的是111,所以输入的是111) (02) 退出数据库 exit (03) 查看数据库 show d ...

  6. Linux今日疑问

    问题一:who -r没有反应 ========== 首先我查询了运行等级的含义. 0: 关机 1: 单用户 2: 无网络的多用户 3: 命令行模式 4: 未用 5: GUI(图形桌面 模式) 6 : ...

  7. Redis Cluster高可用集群在线迁移操作记录【转】

    之前介绍了redis cluster的结构及高可用集群部署过程,今天这里简单说下redis集群的迁移.由于之前的redis cluster集群环境部署的服务器性能有限,需要迁移到高配置的服务器上.考虑 ...

  8. smarty半小时快速上手教程

    一:smarty的程序设计部分: 在smarty的模板设计部分我简单的把smarty在模板中的一些常用设置做了简单的介绍,这一节主要来介绍一下如何在smarty中开始我们程序设计.下载Smarty文件 ...

  9. HTTP协议详解(一)

    1 http协议介绍 1.1 简单介绍  HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consort ...

  10. java使用spark/spark-sql处理schema数据

    1.spark是什么? Spark是基于内存计算的大数据并行计算框架. 1.1 Spark基于内存计算 相比于MapReduce基于IO计算,提高了在大数据环境下数据处理的实时性. 1.2 高容错性和 ...