Usaco translation: Three Questions of Usaco (2)

Source: Internet
Author: User

Usaco JAN (Topic two)

I. Overview of the topic

Name of Chinese title

Stacked Hay

Divided hay

Cow Running

Name of English title

Stacking

Baleshare

Cowrun

Executable file name

Stacking

Baleshare

Cowrun

Enter file name

Stacking.in

Baleshare.in

Cowrun.in

Output file name

Stacking.out

Baleshare.out

Cowrun.out

Time limit per test point

1 seconds

1 seconds

1 seconds

Number of test points

10

10

10

Score per test point

10

10

10

Comparison mode

Full-text comparison

Full-text comparison

Full-text comparison

Second, running memory limit

Running Memory caps

M

M

M

Note: Thank Lao Hu for his translation. "The error will be there, the statement is not so smooth ..."

1. Stacked hay {Bronze 2}

"Problem description"

There are (1 <= n <= 1,000,000, n is odd) heap hay, press 1. n number, at the beginning of each heap height is 0,FJ given K (1 <= k <= 25,000) instructions, each instruction contains two spaces separated by an integer, such as "10 13", to 10,11,12,13 the four piles of hay stacked with a bundle of hay, that is, the height of the increase of 1.

FJ wanted to know what the median of the n heap of hay height was after the hay was finished.

"File Input"

The first line, two positive integers n and K.

2nd.. K+1 lines, two integers a B (1 <= A <= b <= N) per line, representing an instruction.

"File Output"

An integer that represents the median.

"Input Sample"

7 4

5 5

2 4

4 6

3 5

"Output Example"

1

"Sample description"

After the heap, the height is 0,1,2,3,3,1,0. After sorting is 0,0,1,1,2,3,3, the median number is 1.

2. Sub- hay {silver title 2}

"Problem description"

FJ has n (1 <= n <= 20) Bales of hay, hay I weighs s_i (1 <= s_i <= 100), and he wants to divide hay to 3 farms as evenly as possible.

He wants the maximum amount of hay to be allocated as small as possible, for example, b_1,b_2 and B_3 are three values after allocation, assuming b_1 >= b_2 >= b_3, he wants the value of b_1 to be as small as possible.

For example: The weight of 8 packs of touches are: 2 4 5 8 9 14 15 20, a distribution scheme that satisfies the requirements is

Farm 1:2 9 b_1 = 26

Farm 2:4 8 b_2 = 26

Farm 3:5 B_3 = 25

Please help FJ calculate the value of b_1.

"File Input"

The first line, an integer n.

2nd.. N+1 lines, one integer per line, representing the weight.

"File Output"

A row, an integer that represents the value of the b_1.

"Input Sample"

8

14

2

5

15

8

9

20

4

"Output Example"

26

3. Cow running {Gold question 2}

"Problem description"

FJ and Bessie designed a new running game for the cows. The runway is circular with a circular length of (2 <= M <= 1,000,000,000) and the cows are at the same starting position. This game is a total of N (1 <= n <= 14) wheels, with a 8N card to control each round of running distance, each card has a number x_i (0 <= x_i < M).

In each round, the FJ takes out the top 8 cards and then takes out the 8 top or bottom 4 sheets. Then, Bessie from the 4 cards out of the top or bottom 2, the above a figure of x_top, the following figure is X_bottom, then the cow first run r*x_top distance (r means the distance the cows have run), and then run X_bottom distance.

FJ worry that cows are too tired to return to the starting point, when the game is over, if the cows leave the starting distance of more than K (0 <= K <=floor (M/2)), then they will not return to the starting point.

The problem is that when FJ chooses the right strategy, the cows are able to return to their starting point, no matter how Bessie takes the cards. For each round, your task is to decide which 4 cards to take. In the input data, Bessie's every choice is known, but FJ's next choice should be assumed to be unknown, no matter what Bessie chooses, FJ's choice is to ensure the cows can return to their starting point.

"File Input"

The first line, 3 integer n,m,k separated by a space.

The second line, n characters, if the first I character is T, indicates that the first round of Bessie chooses the above 2 cards, if B, then selects the following 2 cards.

3rd.. N+2 lines, each row contains 8 numbers, indicating the top 8 cards (top-down) numbers at the beginning of each round.

"File Output"

A row, a string containing n characters, if the first character is T, the FJ selects the 4 cards above, and if B, the 4 cards below are selected. If there is more than one solution, the output of the smallest dictionary sequence.

"Input Sample"

2 2 0

Tt

1 0 0 0 0 0 0 1

0 1 1 1 0 0 1 0

"Output Example"

TB

"Sample description"

Note that FJ before choosing a card, he was treated as if he didn't know Bessie's next choice, otherwise he could have chosen B twice.

Usaco translation: Three Questions of Usaco (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.