线性结构——单调栈与单调队列
Alex_McAvoy
想要成为渔夫的猎手
展开
-
线性结构 —— 单调栈与单调队列
【单调栈】1.原理单调栈,就是栈内元素保持一定单调性(单调递增或单调递减)的栈,即从栈底到栈顶单调递增或递减。对于单调递增的栈,如果栈为空或入栈元素值大于等于栈顶元素值,则入栈;否则,若入栈会破坏栈的单调性,因此需要将比入栈元素大的元素全部出栈。对于单调递减的栈,如果栈为空或入栈元素值小于等于栈顶元素值,则入栈;否则,若入栈会破坏栈的单调性,因此需要将比入栈元素小的元素全部出栈。...原创 2019-02-10 12:17:31 · 695 阅读 · 0 评论 -
Bad Hair Day(POJ-3250)
Problem DescriptionSome of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows th...原创 2018-06-29 16:53:40 · 464 阅读 · 0 评论 -
Non-negative Partial Sums(HDU-4193)
Problem DescriptionYou are given a sequence of n numbers a 0,..., a n-1. A cyclic shift by k positions (0<=k<=n-1) results in the following sequence: a k a k+1,..., a n-1, a 0, a 1,..., a k-1...原创 2019-02-10 19:19:07 · 413 阅读 · 0 评论 -
Second My Problem First(HDU-3706)
Problem DescriptionGive you three integers n, A and B. Then we define S i = A i mod B and T i = Min{ S k | i-A <= k <= i, k >= 1} Your task is to calculate the product of T i (1 <= i ...原创 2019-02-10 19:19:52 · 234 阅读 · 0 评论 -
Passing the Message(HDU-3410)
Problem DescriptionWhat a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten are prepared to have an excursion. Before kicking off, teacher Liu tells them to...原创 2019-02-11 20:03:03 · 310 阅读 · 0 评论 -
Largest Rectangle in a Histogram(HDU-1506)
Problem DescriptionA histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the fig...原创 2019-02-10 18:23:22 · 346 阅读 · 0 评论 -
City Skyline(POJ-3044)
Problem DescriptionThe best part of the day for Farmer John's cows is when the sun sets. They can see the skyline of the distant city. Bessie wonders how many buildings the city has. Write a progra...原创 2018-07-26 01:58:40 · 429 阅读 · 0 评论 -
Beauty Of Unimodal Sequence(HDU-6592)
Problem DescriptionYou are given an array ofnintegersa1,a2,...,an. We define that a sequencep1,p2,...,pk(k∈[1,n])is beautiful if and only if these conditions are met:1≤p1<p2<⋯<pk≤n...原创 2019-09-26 14:50:39 · 283 阅读 · 0 评论