Codeforces Round #386 (Div 2)

Source: Internet
Author: User

A

=w=

B

Qaq

C

^o^

D

Test instructions: Xiao Ming to a+b cup of tea with a total of n cups, there is green tea a cup, black tea B cup. Xiao Ming drank the same kind of tea for the most consecutive K Cup. Ask if there is a scheme to make xiaoming drink the N cup of tea, is the output of any order.

Analysis: Greed

Our goal is to make the same situation as green tea and black tea as possible, so first as much as possible to drink the same as less than the same, if equal to the direct can, if not equal to drink a few, and then continue to drink as much as possible, if the middle can not operate 1

E

Test instructions: Now give n numbers, and then there is a 1 to M, the representative can change any number of a to 1-m, and finally need to ensure that a array of all the number of odd number equals even number, ask the least number of times, as well as the array after the change, of course, there is no way to achieve the situation, output "- 1 ".

Analysis: Thinking Problems

Handle odd and even numbers separately

Open two sets, place a different number in an odd array into a set, and put a different number in an even array into another set

Odd pointer p=1, even pointer q=2

Iterate through the odd array and the number of repeated occurrences in an even array (they need to be broken) each time the number of p+=2,q+=2, of course, if p,q in their own set appears, it will be added again, until there is no occurrence

Of course this only guarantees that the number in the odd array is different, the number of even arrays is different, and the number of odd and even numbers is not necessarily equal

In order to solve this situation, do not leave the odd number > even number

Then we need to start with the increment of p to replace the number of repeated occurrences in the even array until the parity quantity is balanced

In all of the above p,q self-increment operations, once the M is exceeded, the indication is not feasible, output-1

In the course of the operation, the final answer to each position is recorded ans[], compared with the original x[] to get the minimum number of changes

F

Test instructions: A person K time to listen to n music, each music has a happy degree, and then this person can choose to listen to the music full time t,1/2 up to take the whole time, but also to meet the number of listening to half <=m

Analysis: Analog +set

Considering an x song, the best way to do this is to halve the time of the M song that is the longest.

Consider a feasible solution i~j, then for the next feasible solution i+1~x, then x>=j, that is, two pointers are non-single minus, so just get a data structure to maintain this kind of monotonous queue of things

The specific practice is to make two sets that represent a period of time that is not halved and halved.

Every time you judge whether the J pointer can be moved, first look at the half time of the set is full, if not full directly to determine whether to join the half time is legal; if full, the minimum and t[j] size of the set in half time is judged, if T[J] is large, the smallest one is placed in the half time set, T[j] , judging whether it is lawful

For each I pointer, find the furthest j pointer and keep updating the answer

Then I need to delete the I pointer

If I is in the non-halved set, delete directly, if in the half set, delete I will also need to add the largest of the other set in half set

Note that the Set.end () is an open interval, so it is necessary to get its iterator first when taking a set maximum, and then subtract

G

Test instructions: Give the number of each depth node of a tree, and give the number of leaf nodes, ask whether to form a tree, if you can output any one

Analysis: Construction

Consider the minimum number of leaf nodes

The lowest level, and the number of nodes in layer I is more than the number of nodes in the i+1 layer is definitely a leaf node, statistics of the minimum number of leaf nodes, and the comparison given, if not enough, then output 1, otherwise the node is all marked as leaf node

For those many leaf nodes, you can mark as much as possible from the bottom up

Finally, according to the marker output feasible scheme can

First look at what must be a leaf node

Codeforces Round #386 (Div 2)

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.