Problem G: Sequence Number----暴力
来源:互联网 发布:淘宝外卖怎么加入配送 编辑:程序博客网 时间:2024/05/22 03:10
Problem G: Sequence Number
Time Limit: 1 Sec Memory Limit: 1280 MBSubmit: 803 Solved: 192
[Submit][Status][Web Board]
Description
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.
Input
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
Output the answer S in one line for each case.
Sample Input
52 3 8 6 1
Sample Output
3
题目链接:http://acm.hzau.edu.cn/problem.php?cid=1029&pid=6题目的意思就是新定义一个序列,定义i<j,a[i]<+a[j],问你最大的j-i的长度是多少。
竟然拿了个一血,我的做法不正规,但是过了,过了。。。
暴力,优化第二层for,特判5,4,3,2,1这种情况。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int a[100000];int main(){ int n; while(~scanf("%d",&n)){ bool flag=false; for(int i=0;i<n;i++){ scanf("%d",&a[i]); if(i!=0&&a[i]>a[i-1]){ flag=true; } } if(!flag){ printf("0\n"); continue; } int ans=0; int k=0; for(int i=0;i<n;i++){ k=max(k,i+1); for(int j=k;j<n;j++){ if(a[j]>=a[i]&&j-i>ans){ ans=j-i; k=j; } } } printf("%d\n",ans); } return 0;}
- Problem G: Sequence Number----暴力
- Problem 14 Longest Collatz sequence(暴力)
- HDOJ-----1005---Number Sequence暴力枚举
- ZOJ Problem Set - 2105 Number Sequence
- HDU Problem 1711 Number Sequence 【KMP】
- POJ 1019 Number Sequence (二分查找+暴力打表)
- 【矩阵快速幂】UVA 10698 G - Yet another Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- Number Sequence
- JQuery学习笔记
- libdecodeqr库不能识别大角度二维码问题解决
- 整理的前端面试题2
- Android Studio 与 Unity3d交互(一)
- SQLite数据库---数据库的基本操作
- Problem G: Sequence Number----暴力
- [剑指offer]重建二叉树
- Ubuntu16.04安装Macbuntu 秒变Mac os
- AS打包apk及常见错误解决办法Error:(4) Error: "ssdk_instapager_login_html" is not translated in "en" (English)
- 屏蔽android ota升级包时间戳比较
- CSDN日报20170424 ——《技术方向的选择》
- jenkins复制项目插件、Fir.im、SCM、multibranc链接推荐
- Mysql的基本操作
- Navicat设置字段类型