POJ-2452 Sticks Problem 二分+RMQ 题目链接: https://cn.vjudge.net/problem/POJ-2452 题目大意: 给出一个数组a,求最大的j-i满足 i<j && a[i] ... a[j]中最大值为a[j],最小值为a[i]。 思路: 可以枚举i,然后二分找出满足的最大的j 首先,先二分找出最大的r,满足从a[i]到a[j]的最小...
poj 2452(RMQ+二分) 解题思路:这题实际上就是求某区间上的最值问题,可以先枚举区间的起始位置,然后二分去搜索比起始位置大的数且位置最远(这里可以用RMQ算法区间内的最小值),找到之后再利用RMQ算法找这段区间内的最大的,如果这段区间的长度比当前的最优值大,那么更新。详细的见代码。 #include<iostream> #...
http://poj.org/problem?id=2452 题意:在区间[1,n]上找到满足 a[i]<a[k]<a[j] (i<=k<=j) 的最大子区间 (j-i)如不存在输出 -1. 思路:枚举i,找到 i右边第一个不大于(不是小于)a[i]的数a[k](二分查找+RMQ某段区间的最小值是否小于a[i].最后确定到一个点),于是 我们可以得到在区间[...
POJ_2452 Sticks Problem 【ST表 + 二分】 一、题目 Sticks Problem 二、分析 对于ii和jj,并没有很好的方法能同时将他们两找到最优值,所以考虑固定左端点ii。 固定左端点后,根据题意,a[i]a[i]是最小值,那么现在的问题就转化成了求以a[i]a[i]为左端点最小值的范围内,找到一个最大值a[j]a[j]的j...
POJ-2452-Sticks Problem(二分+RMQ) Description Xuanxuan has n sticks of different length. One day, she puts all her sticks in a line, represented by S1, S2, S3, ...Sn. After measuring the length of each stick Sk (1 <= k <= n), she finds that for some sticks Si and Sj (1<...
题目链接:POJ - 2452 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const int maxn=50010; 7 8 int qmax[maxn][30],qmin[maxn][30]; 9 int a[maxn]; 10 int...
poj2452 Sticks Problem——双方向单调栈 Sticks Problem Description Xuanxuan has n sticks of different length. One day, she puts all her sticks in a line, represented by S1, S2, S3, ...Sn. After measuring the length of each stick Sk (1 <= k <= n), she finds that for some sticks ...
[POJ2452] Sticks Problem Description Xuanxuan has n sticks of different length. One day, she puts all her sticks in a line, represented by S1, S2, S3, ...Sn. After measuring the length of each stick Sk (1 <= k <= n), she finds that for some sticks Si and Sj (1<= i < j...
Output the maximum value j - i in a single line. If there is no such i and j, just output -1. Sample Input 4 5 4 3 6 4 6 5 4 3 Sample Output 1 -1 Source POJ Monthly,static 1#include <iostream>2#include <cstdio>3#include <cstring>45usingnamespacestd;67intdp_max[60000][...
Output the maximum value j - i in a single line. If there is no such i and j, just output -1. Sample Input Sample Output Source POJ Monthly,static 4 5 4 3 6 4 6 5 4 3 1 -1 //这题对于我来说,难点是这个二分查找、第一次知道原来可以这样二分查找//求最大的 j-i(j>i) 对于...