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 ...
随机推荐
- java.lang.IllegalStateException: Ambiguous mapping found
原因:Controller 出现相同的url映射 参考: https://blog.csdn.net/u010892841/article/details/52136256
- D - Stone Division HackerRank - stone-division (博弈+搜索)
题目链接:https://cn.vjudge.net/problem/HackerRank-stone-division 题目大意:给你n,m,然后是m个数.每一次你可以选择一个a[i],如果能被n整 ...
- shell编程 之 文件包含
解释:就是在一个脚本中引用或者运行其他脚本的文件. 常用格式:. filename 或者 source filename 实例:/hehe文件夹下有两个文件:t2.sh 和t3.sh t2.sh的内容 ...
- 20165237 学习基础和C语言基础调查
学习基础和C语言基础调查 一.技能学习与特长 你有什么技能比大多人(超过90%以上)更好? 我的爱好和技能说实话挺广泛的.如果要挑出来一个很擅长的话,我觉得应该是钢琴. 针对这个技能的获取你有什么成功 ...
- Nginx系列6:对称加密与非对称加密各自的应用场景
强推:推荐一篇通俗易懂的对称加密和非对称加密的文章:https://segmentfault.com/a/1190000004461428 推荐一篇文章:对称加密算法与非对称加密算法的优缺点:http ...
- python基础-----异常问题
---恢复内容开始--- 当发生python不知所措的错误时,python会创建一个异常对象, 如果你编写处理该异常的代码,程序将会继续运行: 如果你未对异常做任何处理,程序将会停止,并显示一个tra ...
- [转] Implementing a CNN for Text Classification in TensorFlow
Github上的一个开源项目,文档讲得极清晰 Github - https://github.com/dennybritz/cnn-text-classification-tf 原文- http:// ...
- [BugBounty] Sleeping stored Google XSS Awakens a $5000 Bounty
来源:https://blog.it-securityguard.com/bugbounty-sleeping-stored-google-xss-awakens-a-5000-bounty/ 理解 ...
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
- 1、git基础介绍及远程/本地仓库、分支
1. Git基础介绍 基于Git进行开发时,首先需要将远程仓库代码clone到本地,即为本地仓库.后续大部分时间都是基于本地仓库上的分支进行编码,最后将本地仓库的代码合入远程仓库. 1.1. 远程仓库 ...