2019.10.6 room training match

A priority queue or tree line, looking for a nature

 


 

T1:

Questions surface:

As we all know, the poor family has nine mine.

You can put the poor at home abstracted into a number of mine shafts. Nn family has poor mineral species, ii kind of ore may be obtained from [li, ri] mining any position.

This summer, geography teacher gave a list of the poor: the poor summer job is to gather together these ores. In order to ensure the safety poor, poor father selected m relatively safe mining sites, mining sites coordinates of the ii th of ai. The poor can only choose one of the mining ore mining point she needs.

The poor girl is a sloppy. Not long after the beginning of the summer, put the poor teacher's list lost. The only clue is that all the ore on the list are some poor home: a total of 2n-12n-1 possible list.

The poor now want to know, in all the list of possible tasks, how many she can fully gather together in one safe mining sites.


 

answer:

They have been their own ideas card, wow, hanpiLKX , consider how to handle duplicate, if there is inclusion and exclusion, then, it is to separate each mining point of view, however did not use, can be included before the current contribution of mining point, for the maintenance intervals information beg you to think about the tree line, okay?

For the repetition interval, we interval minus 1, then the current contribution of mining sites is 2 ^ (total) -2 ^ (- 1), of course, can also be used to modify the difference converted to a single point, the l -1, r + 1 +1;

Of course there is a written priority queue, the general idea as above (the feeling that violence ????)

 

 


 

T2:

Questions surface:


The poor do not like the sequence of brackets, but she always found some people like the topic parentheses sequences.

In order to let the whole world can feel her pain, she wanted to write a converter: it can convert a string lowercase same way as normal growth of legitimate parentheses sequence.

In poor idea, such a converter needs to satisfy the following two conditions:

  1. If the result of the sequence in parentheses must be valid, i.e. if the left and right parentheses must match.

  2. For a bunch of matches left and right parentheses, they are the location of the original lowercase letters must be the same.

For example, for a string aabaab, () (()) is a valid answer, and () () () does not satisfy the second condition, (((()) does not satisfy the first condition.

The poor found for a lowercase string, sometimes there are a lot of sequences in parentheses to meet the conditions, sometimes not one.

so the poor are given a lowercase string, she wants you to help her count, how many different sub-string can meet converted into legitimate parentheses sequence.


 

answer:

First, violence is an enumeration bottom of the stack (can be understood as the left point), then do it just like a normal bracket matching, it popped encountered the same, not the same as add to the mix, if the stack is empty it means that the match is successful, attention ! ! ! This question can not have restrictions letters to all the hash brackets

Time complexity of O (n ^ 2)

Consider optimization, we noticed a nature: when the stack of elements in different times after the bomb stack is the same, it shows the sequence between these two positions is to meet the conditions, then consecutive encountered on statistics (two of two matching is n * (n-1) / 2)

 


 

Guess you like

Origin www.cnblogs.com/lkx422/p/11628095.html