Winter training - personal training game 1

To be completed Topic:

answer

A. Left-handers, Right-handers and Ambidexters

Subject to the effect:

There are three attributes of people a, b, ab. Wherein ab person may be both a property to be as b. If asked to form a team requires a, b properties of each half people, the largest number of this team is how much?

analysis:

May assume \ (A <B \) , then divided into two cases:

  1. When \ (a + ab <b \ ) when the answer is \ (2 (A + ab &) \) .
  2. When (a + ab \ le b \ ) \ when ab filled with a first, a number such that the number and b is the same, then divided in half again to ab a, b. The answer is \ (2 (b + (ab - (b - a)) / 2) \)

So water is a problem ......

B - Intercepted Message

Subject to the effect:

Two sequences into the same number of blocks, such that each block of the same. Q can be divided into a maximum of a few?

analysis:

The idea is similar to the double pointer, when the first sequence and the second sequence is less than when the movement of the pointer above the right until the two identical sequences, then adding a number of blocks, and then the two sequences reset (or vice versa). Until the two pointers point to the end of the sequence.

C - Zebra

Subject to the effect:

Sequence given section 01, can be divided into several sub-Q sequence, such that each subsequence is zero and the end, and 01 are alternately.

analysis:

Beginning misread the title ...... missed a 01 alternately this condition, I wa until the situation got.

In fact, do not think so much, you can direct simulation. The answer queue for maintenance. And then open a data structure (I use the queue) marks the current end of the answer queue is 0 or 1 at the end.
Then again sweep from left to right:

When confronted 1, query whether the current queue 0 at the end of the answer, yes, the answer is inserted into the queue, and the marking to the end of 1. No, -1 can be directly output.

When confronted with 0, query whether there is currently an answer at the end of the queue, there is, insert and modify the mark, no, the more open a queue, it indicates that this is a new queue, and is ending in 0.

After Saowan, sequence number is the number 0 at the end of the queue. Note that this time, one end of the queue should be empty (For this reason, I wa the situation got) here must make a judgment. The rest is a sequence of output queue to pop up constantly.

G. Feed the cat

Subject to the effect:

To the effect that at a given point in time, cats have a hunger H value, and then every minute point D will be out hunger value, you need to buy some bread to the cat. Each bread reduce hunger N-point value. Each toast price is C. But after 20 o'clock when the bread will be discount of twenty percent. He asked to reduce the cat's hunger value less than or equal to the minimum cost of 0 is.

analysis:

Obviously 20: Immediately after buying 00.
20:00 before 20:00 when calculated immediately bought and bought cost, whichever is smaller that one on the line.

H - Not simply beatiful strings

Subject to the effect:

If a string is defined to contain only two different letter, then this character string is unique.
Given a string, if asked can be divided into two special strings.

analysis:

Calculating the number of letters title ...... water species, obviously, when several or more than 4 to 1, can be divided into two special strings.
When several letters of 4 must be.
2,3 when the number of species, as long as the number of these types of letters is not 1, then certainly points.

Finished I found out that all the water problem ...... hand speed Hao Mana

Guess you like

Origin www.cnblogs.com/ljxtt/p/12199402.html