[BZOJ3831] [POI2014] Little Bird monotonous queue, & #39; & #39; series ., Bzoj3831poi2014

Source: Internet
Author: User

[BZOJ3831] [POI2014] Little Bird monotonous queue, ''no more brush it on the soil'' series ., Bzoj3831poi2014

Question:

I am sticking to the Black translation of bzoj ~

There are n trees in a row. The height of the I-th tree is Di. MHY wants to go from the first tree to the nth tree to find his sister. If MHY is in the I tree, he can jump to the I + 1, I + 2,..., I + k tree. If MHY jumps to a tree that is not less than the current tree, the fatigue value will be + 1; otherwise, it will not. In order to have the power to play with the girl, MHY should minimize the fatigue value. Question:

Monotonous queue breaks the question, no more.

It is said that the bzoj poi has always been a local tyrant, and it is not enough to brush it ..


Let's look at the code again. There are comments in it.

Code:

# Include <cstdio >#include <cstring> # include <iostream> # include <algorithm> # define N 1001000 # define inf 0x3f3f3fusing namespace std; int q [N], top, tail, n; int f [N], high [N]; bool cmp (int ha, int fa, int hb, int fb) // returns whether A is better than B {return fa = fb? Ha> = hb: fa <fb; // I. The same price must be high. // II. Different prices must be cheap. // This is because: // ① the price is high: no explanation. // ② The two are the same height: do not explain. // ③ Cheap dwarf: it can change from 1 to infinitely high. // or it can be transferred back to the dwarf tree .} Int main () {// freopen ("test. in "," r ", stdin); int I, j, k, g; scanf (" % d ", & n); for (I = 1; I <= n; I ++) scanf ("% d", & high [I]); for (scanf ("% d", & g); g --;) {scanf ("% d", & k); q [top = tail = 1] = 1; for (I = 2; I <= n; I ++) {while (top <tail & I-q [top]> k) top ++; f [I] = f [q [top] + (high [I]> = high [q [top]); while (top <= tail & cmp (high [I], f [I], high [q [tail], f [q [tail]) tail --; q [++ tail] = I;} printf ("% d \ n", f [n]);} return 0 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.