Sequence Number
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的更多相关文章
- 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 ...
- [crypto][ipsec] 简述ESP协议的sequence number机制
预备 首先提及一个概念叫重放攻击,对应的机制叫做:anti-replay https://en.wikipedia.org/wiki/Anti-replay IPsec协议的anti-replay特性 ...
- 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)
原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ from:ht ...
- InnoDB: The log sequence number in ibdata files does not match
InnoDB: The log sequence number in ibdata files does not matchInnoDB的:在ibdata文件的日志序列号不匹配 可能ibdata文件损 ...
- hzau 1205 Sequence Number(二分)
G. Sequence Number In Linear algebra, we have learned the definition of inversion number: Assuming A ...
- Thread <number> cannot allocate new log, sequence <number>浅析
有时候,你会在ORACLE数据库的告警日志中发现"Thread <number> cannot allocate new log, sequence <number> ...
- ORA-02287: sequence number not allowed here问题的解决
当插入值需要从另外一张表中检索得到的时候,如下语法的sql语句已经不能完成该功能:insert into my_table(id, name) values ((select seq_my_table ...
- [转] 理解TCP序列号(Sequence Number)和确认号(Acknowledgment Number)
点击阅读原译文 原文见:http://packetlife.net/blog/2010/jun/7/understanding-tcp-sequence-acknowledgment-numbers/ ...
- pymysql.err.InternalError: Packet sequence number wrong - got 45 expected 0
原因: 使用了多线程,多线程共享了同一个数据库连接,但每个execute前没有加上互斥锁 方法: 方法一:每个execute前加上互斥锁 lock.acquire() cursor.e ...
随机推荐
- Javascript入门(四)条件控制语句
一.条件控制语句 1. if <script type="text/javascript"> var num = 1 if( num == 3 ){ alert(&qu ...
- java后台获取参数乱码
String title = getParam("searchTitle"); title = new String(title.getBytes("iso8859-1& ...
- 关于Sublime Text 3的几个问题总结
问题1:Sublime Text 3的注册码. 注册码网上搜有很多,所以可以去网上找.我现在给的可能以后就不能用了,而且我也是网上找的... 这个现在最新版本是可用的. —– BEGIN LICENS ...
- 【转载】 python-星号变量的特殊用法
原文链接:https://www.qingsword.com/qing/python-12.html 引言 在Python中,星号除了用于乘法数值运算和幂运算外,还有一种特殊的用法"在变量前 ...
- android 网络编程 HttpGet类和HttpPost类使用详解
虽然在登录系统中使用了Web Service与服务端进行交互.但是在传递大量的数量时,Web Service显得有些笨拙.在本节将介绍移动电子相册中使用的另外一种与数据库交互的方法.直接发送HTTP ...
- Path Sum I && II & III
Path Sum I Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that ad ...
- Django 的系统时区设置 RPC
PRC Deprecated +08:00 +08:00 Link to Asia/Shanghai settings.py 文件的设置项: TIME_ZONE = 'PRC' 来源 ...
- Session、LocalStorage、SessionStorage、Cache-Ctrol比较
1.Session Session是什么? 服务器通过 Set-Cookie给用户一个sessionIdsessionId对应 服务器 内的一小块内存每次用户访问服务器的时候,服务器就听过Sessio ...
- python类的内建方法
研究email源码学到的 class test(): """Class for generating text/* type MIME documents."& ...
- 题解-hdu2866 Special Prime
Problem hdu-2866 题意:求区间\([2,L]\)有多少素数\(p\)满足\(n^3+pn^2=m^3\),其中\(n,m\)属于任意整数 Solution 原式等价于\(n^2(p+n ...