Noip simulation question solution set

Source: Internet
Author: User

Some good questions and solutions have been seen in the simulation questions recently.

 

Higher thinking:

Nuclear Power Plant Problems

A nuclear power plant has n pitfall containing nuclear material, which are arranged in a straight line. If a nuclear material is put into M consecutive pits, it will lead to an explosion. Therefore, nuclear material may not be put in some pits.
Task: for a given n and M, calculate the total number of solutions for placing nuclear substances without explosion

Input: Only one row of the input file, two positive integers n, m (1 <n <50, 2 ≤ m ≤ 5)

Output: the output file has only one positive integer (s), indicating the total number of solutions.

 

Use the upgraded thinking. The number of solutions with N pits not exploding is f [N], so we assume that N is the previous solution.

As we know, we only need to consider how to place the nth pitfall (the order is from left to right ). We consider two situations:

1. When n is put into a substance, there are two possibilities: one is because we put a continuous 1-1, and now it will explode, so this case has f [N-1-m] case, this is to cut off. One is that there will be no explosion, then the number of solutions is f [N-1]. So the solution to put this pit into material has f [N-1]-f [N-1-m].

2, when n this pit is not put into the material, then the solution is directly f [N-1].

So f [N] = f [N-1] + F [N-1]-f [N-1-m]

F [0] = f [-1] = 1

 

 

Dynamic Planning: the first problem of optimization should be thought of as dynamic

Egg Experiment

There is an e nest on the villa of a professor at Ural University. The professor is very interested in this nest. After careful observation, he found several eggs in the nest. So he wanted to use these eggs for a test. Test the strength of the egg.

These eggs should have the same hardness. There is a non-negative integer e. If you throw an egg from the first layer of the building, but it won't break, but if you throw an egg from the second layer e + 1 (including a layer higher than e + 1, the egg will be broken. You need to do a set of experiments to find out E. The simplest method is to perform layer-by-layer testing. However, if you have multiple egresses, you do not need to use the stupid method. You can find e in less times. Note that the number of times here refers to the worst case for your method and it cannot be used again after it is broken, and E can be 0.

If the experiment reaches the highest level, it is considered that e takes the highest level of layers.

Input: one row. The number of eggs is n and the number of floors in the building is n, k <= 1000. (A space in the middle)

Output: the minimum number of labs.

 

10 choices for the first test-Layer 1 to layer 10

If you select Layer 3, the worst case is e! = 3. If e <3, the eggs will be broken (key !), Then a [2] [1] is required.

If e is greater than 3, a [7] [2] is required. In the worst case, take the maximum values of two values and Add 1.

If there are n floors and M eggs, they are actually

For (I = 1; I <= N; I ++) a [n] [m] = min {1 + max {A [I-1] [s-1], A [n-I] [m]}

Of course, pay attention to pruning.

1000 floors, up to 10 eggs

 

Wooden stick Group

[Description]

With n sticks, You need to divide them into as many groups as possible to meet the length and equality of each group of sticks. You cannot cut the sticks. Output the sum of the wood rod lengths in the next group of optimal solutions.

[Input format]

The first line is an integer n. The next n integers indicate the length of N wooden sticks.

[Output format]

One integer in a row, indicating the sum of the wood stick lengths

[Example input]

4

2 5 3 4

[Sample output]

7

[Data Scope]

70% data guarantee n <= 8

100% data guarantee n <= 50

We can consider the number of enumeration groups (obviously <= 50, and can divide sigma (A [I]). Then, we do not need to consider the order of the number of groups, we only need to consider whether there are enough elements in A group (but we need to use the least element), so we use the 01 backpack for DFS, each time, you can determine whether to find as few elements as possible in the remaining elements to match the value of sum/group. You must pay attention to initialization, because I have been debugging for a long time ..

 

Expanding Euclidean is Y-= A/B * X. It's not y-= x * A/B. It's the lower limit !!!!!

 

Lonely programmers

[Description]

There are two lonely programmers J and Y. J said that he could knock 8000 words in two minutes, and Y did not believe it, so J played a typing competition with Y's 4 kb/min robot. The robot knocked garbled characters at a high speed, and J found the key to help him speed beyond his hand: Ctrl. J. You can perform the following operations at different times:

1. Double-click a character.

2. Press CTRL-A

3. Press CTRL-C

4. Press CTRL-V

(For more information, see the experiment in Notepad)

You need to set an operation order so that J can enter the maximum number of characters in N milliseconds.

[Input file]

The fifth integer in the first line is n cost input cost ctrla cost ctrlc cost ctrlv, and the four cost correspond to the number of milliseconds required to perform four operations respectively.

[Output file]

A line of one integer indicates the maximum number of characters that can be entered

[Example input]

14 10 1 1 1

[Sample output]

2

[Data Scope]

30% data guarantee n ≤ 10

100% of Data guarantee: 1 ≤ n ≤ 1,000; 1 ≤ cost ≤ n

 

I was wrong with qaqsad at the beginning .. We only need to set the State d [I] to indicate the maximum number of words that can be played at the I moment, then d [I] = max (d [I-ctrla-ctrlc-ctrlv-J * ctrlv] * (J + 1 .. It's easy to think about it. So we will see various types of questions in the future, that is, if an operation depends on other operations, we will directly consider these operations as a whole (but we need to update them from start to end)

 

 

Match a public string with the asterisk (*)

There are strings A and B. The character "*" in "A" indicates that any string (including an empty string) can be assigned a value in this field and asked if it can match a and B.

If the status D [I, j] indicates whether the pre-I and pre-j In A can be matched

D [1, 0] = true when a [1] = '*'

D [0, 0] = true

D [I, j] = d [I-1, J-1], a [I] = B [J]

D [I, j] = d [I-1, J-1] | D [I-1, J] | D [I, J-1], a [I]! = B [J]

 

 

Status compression:

Youyou

A group of friends explored in the mountains and they came to the cave. All donkey friends must pass through the cave. But the cave is too narrow to pass through the cave at the same time. Therefore, they can only be divided into groups to cross the cave. However, they only have one flashlight. Therefore, after a group of people cross the cave, they must bring a flashlight back until the last person crosses the cave.

There is a bridge in the cave. Every time a person crosses the cave, he must cross the bridge at the same time. However, the load-bearing capacity of the bridge is limited and the quality of the bridge cannot exceed M. Otherwise, the bridge will collapse. Everyone's weight has been known beforehand. There can be a single donkey friend crossing the cave. Of course, if there are more than one group crossing the cave at the same time, then everyone must have at least one person he trusts in the group. Given an adjacent matrix T, T [I, j] is equal to "Y", it indicates that I trust J; otherwise, I do not trust J. Each person walks at different speeds. Therefore, when a group of people walks, they follow the slowest pace. You already know the time required for each person to cross the cave separately. Find the minimum time required for everyone to pass through the cave. If the cave cannot be crossed, output-1.

[Input file]

The first line has two integers, N and M, indicating the total number of people and the load of the bridge.

The next line contains N integers, indicating the quality of each person. The next row contains N integers, indicating the time required for each person to pass through the cave.

Next is a character matrix of n × N, which contains only 'y' and 'n', indicating the trust matrix.

[Output file]

An integer that represents the minimum time. The period-1 indicates no solution.

[Data Scope]

1 ≤ n ≤ 13, 1 ≤ m ≤ 5000

 

We should think of the pressure when we see n <= 13. We consider two states: Status 1 and status 2. Indicate the current person. However, status 1 indicates that no holes have been made, and status 2 indicates that the holes have been made. Then, when the status is changed to status 2, it is obvious that the people in the two statuses are routed to the holes (and the other way around ). Therefore, we pre-process all possible conditions on both sides, and then calculate the minimum cost for each case, so we can connect to the edge in these states. The final state (everyone) that has never entered the hole is the shortest path. The answer is the status (everyone) of the hole ).

 

We can see that the data range is less than or equal to 15.

 

Shortest Path:

Escape

Xiao J was infected with a split bacteria during a trip. After one minute, the bacteria split into two bacteria of the same weight, one of which no longer splits, the other splits after one minute. Xiao J wants to find bactericidal herbs as soon as possible, but there are not many ways to walk. There are N pools and M channels in the mountains. Each road connects two pools. It takes some time to walk through this road. Small J was infected in the S pool, and the bactericidal herbs grew in the T pool. Every time J passes through a pool, he needs to take a sip of water to supplement his physical strength, but bacteria also change: All bacteria are combined into one, and the weight is the sum of the weight of all bacteria, split after one minute. However, Xiao J does not know this. Every time he goes through a pool, he will still drink water. You need to draw a route from pool s to pool t for small J to minimize the bacterial weight when it reaches pool T. Data is guaranteed to have only one group of solutions.

[Input format]

The fourth integer n m s t in the first line

In the next m row, each row contains three integers, l r w, indicating that there is a road between pool l and pool R, which takes w minutes (drinking water does not take time ). There may be multiple roads between the same pair of L-R

[Output format]

The first line is an integer k, indicating the route length.

The next line contains k integers, indicating each point that passes through the route

[Example input]

4 4 1 4

1 2 0

1 3 2

3 4 1

2 4 4

[Sample output]

3

1 2 4

[Data Scope]

30% of Data guarantee n ≤ 50; W ≤ 10

100% of the data is guaranteed to be 2 ≤ n ≤ 10000; 1 ≤ m ≤ 30000; 0 ≤ W ≤ 1000; S = T; L = r

 

Obviously, it can be converted to a triangle inequality of d [v] <= d [u] + d [u] * W [U, V. But for such data, it is obvious that the table will pop up ..... Let's consider this,

D [v] <= d [u] * (1 + W [U, V])->

Log (d [v]) <= Log (d [u] * (1 + W [U, V])->

Log (d [v]) <= Log (d [u]) + Log (1 + W [U, V])

Then we can directly change the edge weight to log and then add them together.

 

Score planning:

Jailbreak

[Description]

There are n consecutive rooms in a prison, each of which has an iron door with Different Hardness and closes several prisoners. One day, the prisoners planned to escape from prison to realize their dreams. They planned to allow people in a continuous room to rush out of the gate to control the jailer. The possibility of success was defined as the number of people in the violence/tie door hardness and. In order to distract the jailer's attention, the number of violent rooms should not be less than l. As an insider in the jailer, You need to develop the most likely solution to success. If multiple groups of solutions exist, either of them is output.

[Input format]

The first line has two integers, n l.

N integers in the second row. The I integer a I indicates the number of people in the I room.

N integers in the third row. The I integer B I indicates the hardness of the iron door in the I room.

[Output format]

A row has two integers, namely, S ~ People in Room T (including S, T) are at war.

[Example input]

3 2

1 2 3

3 2 1

[Sample output]

2 3

[Data Scope]

30% of Data guarantee n ≤ 100,000% of Data guarantee 1 ≤ L ≤ n ≤ 10,000; 1 ≤ a I, B I ≤

 

In fact, I first thought of the score plan when I saw division, but I don't know how to calculate F (t)> = 0 ....

It's actually very simple .... After processing all a [I]-D * B [I], you only need to find the maximum value of the range> = L...

And O (n) can be solved... To maintain a prefix sum, you only need to maintain a minimum prefix sum (based on sum [R]-sum L-1]) and then maintain the maximum value. Then, do not write the wrong check... The return value of my check is bool, and then I can judge in the second part that the check is <-EPS .... Sad ..

 

It indicates that the given length of the interval can be used as the prefix and O (n)

 

If you plan your scores, you can simply push them by yourself:

Let B = sigma (A [I] * X [I])/SIGMA (B [I] * X [I]) B be the most value (that is, the optimal solution ), here, X [I] indicates whether to select I, and both a [I] and B [I] are known.

Let's set f (a) = sigma (A [I] * X [I])-A * sigma (B [I] * X [I])

When F (a)> 0 (assuming that the current is the maximum value of B), we find that

SIGMA (A [I] * X [I])-A * sigma (B [I] * X [I])> 0 is a solution.

SIGMA (A [I] * X [I])/SIGMA (B [I] * X [I])> A, then the left formula is obviously better than, then the expression A can be used directly (meaning there is a better solution for A. In the second part, the explanation is that F (MID)> 0, so l = mid, that is, approaching the lower bound)

Let's look at the deformation of F.

F (a) = sigma (A [I] * X [I])-A * sigma (B [I] * X [I])

= Sigma (A [I]-A * B [I]) * X [I])

Obviously, a [I]-A * B [I] can be obtained directly, so the problem is converted to finding a solution x so that f (a)> 0,

The minimum value is the same.

 

Number Theory:

Decimal limit

[Description]

Xiao J is a strict person. He can only accept limited decimal places, and some numbers make him uncomfortable, such as 0.3. One day, he found that 0.3 can be written as 0.1 in a 3-digit system, and 0.a (A (30) = 10 (10) in a 30-digit system )). So he believed that all rational numbers could be written as finite decimals. However, it is very troublesome to constantly switch to the hexadecimal mode. Now, a small J needs to process a number of rational numbers. You need to tell him that at least a few hexadecimal values are required to make them all write finite decimals.

[Input format]

The first line is an integer n. Next n rows, each row has two decimal integers a B, representing a score

A

B

[Output format]

A hexadecimal integer in a row, indicating the smallest number of hexadecimal digits

[Example input]

2

1 33

1 99

[Sample output]

21

[Data Scope]

100% of Data guarantee n ≤ 1,000; 1 ≤ a, B ≤ 100,000,000

 

Set R = p1 * P2 * .. * PK (PI is the prime number of each other)

Set B = {B | B = p1 ^ T1 * P2 ^ T2 * .. * PK ^ TK (Ti> = 0 )}

Adequacy: For any B in B, A/B can be written as finite decimal places in R base.

Necessity: For any c branch B, the approximate fraction A/C cannot be written as a finite decimal number in the r base.

The % x wildcard of printf ("% x") can directly output the hexadecimal number.

 

 

Count: If counting is not a combination count, it is a recurrence count. Pay attention to the abstraction of the recurrence count!

Incorrect sorting Formula

When N numbering elements are placed in N numbering positions, the number of methods that do not correspond to each element number is represented by D (N), then D (n-1) it indicates that n-1 number elements are placed at N-1 numbers, and the number of methods does not correspond to each other, and so on.

Step 1: place the nth element in a single position, such as position K. There are n-1 methods in total;

Step 2: Put the element number K. There are two situations:

(1) Put It In The position N, then, for the remaining n-1 elements, because the K element to the position N, the remaining N-2 elements have D (n-2) method;

(2) the k-th element does not place it in position n. In this case, there is a D (n-1) method for the n-1 element;

In summary

D (n) = (n-1) [D (n-2) + d (n-1)]

In particular, D (1) = 0, D (2) = 1.

 

Stirling count

The first Stirling number is positive and negative, and its absolute value is the number of K-ring arrangement methods for the project of n elements. Commonly used Representation Methods include S (n, k) and [NK].

In other words, N people are divided into k groups, and the number of grouping methods in which each group is circled in a specific order. For example, S ):

{A, B}, {c, d}

{A, c}, {B, d}

{A, D}, {B, c}

{A}, {B, c, d}

{A}, {B, d, c}

{B}, {a, c, d}

{B}, {A, D, C}

{C}, {a, B, d}

{C}, {A, D, B}

{D}, {a, B, c}

{D}, {A, C, B}

This can be expressed by Directed Graphs.

Given S (n, 0) = 0, S () = 1, S (n + 1, K) = S (n, k −1) + NS (n, k)

Recursive relationship description: Consider n + 1 items, n + 1 can constitute a separate non-empty loop arrangement, so the first n items constitute a non-empty loop arrangement of K-1, the number of items is S (n, k-1); the first n items can constitute K non-empty loop arrangement, and the N + 1 item is inserted to the left of the I item, there are N * S (n, k) methods.

That is, S (n, k) = S (n-1, k-1) + (n-1) * s (n-1, K)

 

The second type of Stirling is the number of methods that define K equivalence classes for N element sets. Commonly used Representation Methods include S (n, k), S (k) n, {nk }.

In other words, N people are divided into k groups. For example, if there are four people: A, B, C, and D. If all people are divided into one group, only all people are in the same group. Therefore, S () = 1. If all people are divided into four groups, only one group can be independent of everyone, so s () = 1; if divided into two groups, it can be a group of A and B, a group of C, a group of C, and a group of B, or a group of C, B, and C, or three of them are in the same group and the other is in the same group, that is:

{A, B}, {c, d}

{A, c}, {B, d}

{A, D}, {B, c}

{A}, {B, c, d}

{B}, {a, c, d}

{C}, {a, B, d}

{D}, {a, B, c}

Therefore, S () = 7.

Given S (n, n) = S (n, 1) = 1, there is a recursive relationship S (n, k) = S (n −1, K −1) + K * s (n−1, K)

Recursive relationship description: Consider n items, n can constitute a separate non-empty set, at this time the first n-1 items constitute a non-empty K-1 unidentifiable set, the number of methods is S (n-1, k-1); The n-1-1 items can constitute K non-empty unidentifiable sets, the N items into any one, in this case, there are K * s (n-1, k) methods.

 

 

Noip simulation question solution set

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.