2023 14th Blue Bridge Cup JAVA Group B Topics

The second time I participated in the Blue Bridge Cup, the phone ran out of battery again, so I only wrote for two and a half hours before handing in (you can’t repeat the handover). Meetings consume a lot of power. This blog was written just after submission, you can check the time hhh.

I just did the first five questions, but the first five questions can be done by searching, enumerating, and base, depending on fate.

04.08, to see when the results will come out.

Table of contents

Question A: Sum of factorials

Question B: Lucky Numbers

Exam C: Array Segmentation

Question D: Total Area of ​​a Rectangle

Question E: Snail

Question F: Merging Regions

Question G: Buy Two Get One Free

Question H: Merge Stones

Question I: Maximum Expenditure

Test Question J: Magic Circle



 


Question A: Sum of factorials

Total score for this question: 5 points

【Problem Description】

Let S = 1! + 2! + 3! + ... + 202320232023!, find the last 9 digits of S. Tip: The first digit of the answer is not 0.

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.


Question B: Lucky Numbers

Total score for this question: 5 points

【Problem Description】

The Harshad number refers to a positive integer that can be divisible by the sum of the digits in a fixed base system. For example, 126 is a Harshad number in decimal because (126)10 mod (1+2+6) = 0; 126

It is also a Harshad number in octal, because (126)10 = (176)8, (126)10 mod (1 + 7 + 6) = 0; at the same time, 126 is also a Harshad number in hexadecimal, because ( 126)10 = (7e)16, (126)10 mod (7 + e) ​​= 0. Xiaolan believes that if an integer is a Harshad number in binary, octal, decimal, and hexadecimal, then this number is a lucky number, and the decimal representation of the 1st to 10th lucky numbers is: 1 , 2 , 4, 6, 8, 40, 48, 72, 120, 126 . . . Now he wants to know what is the 2023rd lucky number? You just need to tell Xiaolan the decimal representation of this integer.

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.


Exam C: Array Segmentation

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 10 points

【Problem Description】

Xiaolan has an array A = [A0, A1, . . . , AN−1] of length N. Now Xiaolan wants to find a subset R1 from the set I = {0, 1, 2, . . . , N − 1} formed by the array subscripts corresponding to A, then R1

The complement set in I is R2. Denote S 1 = ∑

r∈R1 Ar,S 2 = ∑

r∈R2 Ar, we require both S 1 and S 2 to be even numbers, how many different R1s are there in this case? When R1 or R2 is the empty set we will

S 1 or S 2 is regarded as 0.

【Input format】

The first line contains an integer T, indicating that there are T sets of data. Next, enter T sets of data, each set of data contains two lines: the first line is an integer N, representing an array

The length of A; the second line inputs N integers from left to right as A0, A1, . . . , AN−1, and adjacent elements are separated by spaces.

【Output format】

For each set of data, output a line containing an integer representing the answer. The answer may be very large. You need to take the answer modulo 1000000007 and output it.

【Sample input】

2

2 

6 6

2

1 6

【Sample output】

4

0

【Example description】

For the first set of data, the answer is 4. (Note: The numbers in curly brackets indicate the subscript of the element in the array.)

R1 = {0}, R2 = {1}; at this time, S 1 = A0 = 6 is an even number, and S 2 = A1 = 6 is an even number.

R1 = {1}, R2 = {0}; at this time, S 1 = A1 = 6 is an even number, and S 2 = A0 = 6 is an even number.

R1 = {0, 1}, R2 = {}; at this time, S 1 = A0 + A1 = 12 is an even number, and S 2 = 0 is an even number.

R1 = {}, R2 = {0, 1}; at this time, S 1 = 0 is an even number, and S 2 = A0 + A1 = 12 is an even number. For the second set of data, no matter how you choose, the condition is not satisfied, so the answer is 0.

[Evaluation use case scale and agreement]

For 20% of the evaluation cases, 1 ≤ N ≤ 10. For 40% of the evaluation cases, 1 ≤ N ≤ 10 2 . For 100% of the evaluation cases, 1 ≤ T ≤ 10, 1 ≤ N ≤ 10 3 , 0 ≤ Ai ≤ 10 9.


Question D: Total Area of ​​a Rectangle

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 10 points

【Problem Description】

There are two rectangles R1 and R2 on the plane, and their sides are parallel to the coordinate axes. Let (x1, y1) and

(x2, y2) are the coordinates of the lower left corner and upper right corner of R1 in turn, (x3, y3) and (x4, y4) are the coordinates of the lower left corner and upper right corner of R2 in turn, please calculate the total area of ​​R1 and R2? Note: If R1 and R2 have an overlapping area, the area of ​​the overlapping area is only calculated once.

【Input format】

The input is only one line, containing 8 integers, in order: x1, y1, x2, y2, x3, y3, x4 and y4.

【Output format】

An integer representing the answer.

【Sample input】

2 1 7 4 5 3 8 6

【Sample output】

22

【Example description】

The two rectangles in the example are shown in the figure:

[Evaluation use case scale and agreement]

For 20% of the data, R1 and R2 have no overlapping regions. For 20% of the data, one of the rectangles is completely inside the other. For 50% of the data, the range of values ​​for all coordinates is [0, 10^3]. For 100% of the data, the range of values ​​for all coordinates is [0, 10^5].


Question E: Snail

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 15 points

【Problem Description】

On this day, a snail came to the origin of the two-dimensional coordinate system. There are n bamboo poles growing on the x-axis. They are parallel to the y-axis, the bottom ordinate is 0, and the abscissa is x1, x2, ..., xn respectively. The height of the bamboo poles is infinite, and the width is negligible. The snail wants to go from the origin to the first

The bottoms of n bamboo poles are coordinates (xn, 0). It can only crawl on the x-axis or on the bamboo pole, and the crawling speed on the x-axis is 1 unit per second; due to the influence of gravity, the speed of the snail crawling up and down on the bamboo pole is 0.7 units per second and 1.3 units per second, respectively. Second. In order to reach the destination quickly, it casts magic and establishes a portal between the i-th and i+1 bamboo poles (0 < i < n). ai), you can instantly reach the position (xi+1, bi+1) where the height of the i+1 bamboo pole is bi+1 (xi+1, bi+1). Please calculate how many seconds it takes the snail to reach the destination at least.

【Input format】

Input a total of 1 + n lines, the first line is a positive integer n; the second line is n positive integers x1, x2, .

【Output format】

The output is a total of one line, and a floating-point number represents the answer (rounded to two decimal places).

【Sample input】

3
1 10 11
1 1
2 1

【Sample output】

4.20

【Example description】

Snail route:

(0, 0) → (1, 0) → (1, 1) → (10, 1) → (10, 0) → (11, 0), the time spent is 1 + 1 0.7 + 0 + 1 1.3 + 1 ≈ 4.20

[Evaluation use case scale and agreement]

For 20% of the data, ensure that n ≤ 15; for 100% of the data, ensure that n ≤ 10^5, ai , bi ≤ 10^4, xi ≤ 10^9.


Question F: Merging Regions

Time limit: 2.0s Memory limit: 512.0MB Total score for this question: 15 points

【Problem Description】

Xiaolan is playing a farming game. Now he is assigned two square areas of size N × N. These two areas are equally divided according to the specification of N × N, and divided into several small areas with the same area, each of which is either rock or soil, and the adjacent soil in the vertical or horizontal direction A piece of land can be formed. Now Xiaolan wants to merge these two areas along the edge. He wants to know the size of the largest piece of land that can be obtained after the merger (the area of ​​the land is the number of small soil areas in the land)? When merging, the small regions must be aligned. Merge can be performed on any side of two square areas, and two square areas can be rotated 90 degrees, 180 degrees, 270 degrees, 360 degrees, but cannot be flipped up and down or left and right, and the two square areas cannot Overlaps can occur.

【Input format】

An integer N in the first line represents the size of the region. The next N lines represent the first area, and each line has N integers whose value is 0 or 1, and adjacent integers are separated by spaces. A value of 0 indicates that the small area is rock, and a value of 1 indicates that the small area is soil. The next N lines represent the second area, and each line has N integers whose value is 0 or 1, and adjacent integers are separated by spaces. A value of 0 indicates that the small area is rock, and a value of 1 indicates that the small area is soil.

【Output format】

An integer representing the maximum land area that can be produced by merging two regions.

【Sample input】

4
0 1 1 0
1 0 1 1
1 0 1 0
1 1 1 0
0 0 1 0
0 1 1 0
1 0 0 0
1 1 1 1

【Sample output】

15

【Example description】

 The first picture shows the layout of the two regions in the sample. The second picture shows one of the best ways to merge, when the largest land size is 15.

[Evaluation use case scale and agreement]

1 ≤ N ≤ 5 for 30% of the data. For 60% of the data, 1 ≤ N ≤ 15. For 100% of the data, 1 ≤ N ≤ 50.


Question G: Buy Two Get One Free

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 20 points

【Problem Description】

There are N items in a shopping mall, and the price of item i is Ai. Now the shopping mall is conducting a "buy two get one free" promotion, the specific rules are: For every two items purchased, assume that the cheaper price is P (if the price of two items is the same, then P is equal to the price of one of the items ), you can choose one of the remaining goods whose price does not exceed P

2

, get this one for free. Multiple free items can be obtained by repeatedly purchasing 2 items, but each item can only be purchased or freed once. Xiao Ming wants to know how much it will cost at least to get all the products (including purchases and free acquisitions)?

【Input format】

The first line contains an integer N. The second line contains N integers representing A1, A2, A3, . . . , AN.

【Output format】

Output an integer representing the answer.

【Sample input】

7

1 4 2 8 5 7 1

【Sample output】

25

【Example description】

Xiao Ming can buy products with price 4 and 8 first, and get a product with price 1 for free; then buy products with price 5 and 7, and get product with price 2 for free; 1 item. Total cost 4 + 8 + 5 + 7 + 1 = 25. There is no cheaper option.

[Evaluation use case scale and agreement]

For 30% of the data, 1 ≤ N ≤ 20. For 100% of the data, 1 ≤ N ≤ 5 × 10^5, 1 ≤ Ai ≤ 10^9.


Question H: Merge Stones

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 20 points

【Problem Description】

N piles of stones are placed horizontally on the table from left to right. Each pile of stones has the same color, which may be one of color 0, color 1 or color 2. Now to merge the stones, it is stipulated that only two piles of stones with adjacent positions and the same color can be selected for merging each time. After merging, the relative position of the new pile remains unchanged, and the number of stones in the new pile is the sum of the number of stones in the two piles selected, and the color of the new pile of stones will also change cyclically. Specifically: The pile of stones after combining two piles of stones with color 0 is color 1, the pile of stones after combining two piles of stones with color 1 is color 2, and the pile of stones after combining two piles of stones with color 2 is color 0. The cost of this merger is the sum of the numbers of the two piles of stones selected. Given N piles of stones and their initial colors, how many piles of stones can they be merged into at least? If there are multiple answers, choose the one with the smallest total cost of merging. The total cost of merging refers to the sum of the merging costs generated in all merging operations.

【Input format】

In the first line, a positive integer N represents the number of piles of stones. The second line contains N positive integers separated by spaces, representing the number of stones in each pile from left to right. The third line contains N integers with values ​​of 0 or 1 or 2 representing the color of each pile of stones.

【Output format】

A line contains two integers, separated by a space. Among them, the first integer represents the number of stone piles with the least number after merging, and the second integer represents the corresponding minimum cost.

【Sample input】

5

5 10 1 8 6

1 1 0 2 2

【Sample output】

2 44

【Example description】

The image above shows two different ways of merging. The number of stones in each pile is marked in the node, and the color attribute of the current pile of stones is marked in square brackets. The merging method on the left finally leaves two piles of stones, and the total cost of merging is 15 + 14 + 15 = 44; the merging method on the right finally leaves two piles of stones, but the resulting merging The total cost is 14 + 15 + 25 = 54. To sum up, we choose the method with a combined cost of 44 as the answer.

[Evaluation use case scale and agreement]

For 30% of the evaluation cases, 1 ≤ N ≤ 10. For 50% of the evaluation cases, 1 ≤ N ≤ 50. For 100% of the evaluation cases, 1 ≤ N ≤ 300, 1 ≤ number of stones per pile ≤ 1000.


Question I: Maximum Expenditure

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 25 points

【Problem Description】

A new amusement park has opened near Xiaolan's school. As the class monitor, Xiaolan plans to organize everyone to go to the amusement park. It is known that there are a total of N people participating in this event, and there are M entertainment items in the amusement park, and each item needs to buy tickets before entering. The price of tickets is not fixed. The more people who buy a group, the cheaper the unit price. When the number of people who buy a group is greater than a certain threshold, these people who buy a group can enter the project for free. These M entertainment items are independent, so only those who have chosen the same item can participate in the group buying of this item. The relationship between the ticket price Hi of the i-th item and the number of people in the group purchase X can be regarded as a function:

Hi(X) = max(Ki × X + Bi , 0)

max means to take the maximum value among the two. When Hi = 0, it means that the number of group purchases has reached the item's free order threshold. These N people can choose one of the M entertainment items according to their own preferences, or some people are not interested in these entertainment items, and they can also choose not to go to any item. Each person will only choose one entertainment item at most. If multiple people choose the same entertainment item, they will all enjoy the corresponding group purchase price. Xiaolan wants to know at least how much money he needs to prepare, so that no matter what everyone chooses, he has the ability to afford all N people to buy tickets for entertainment projects.

【Input format】

The two integers N and M in the first line represent the number of people participating in the activity and the number of entertainment items respectively. Then there are M lines, each line contains two integers, where the i-th line is Ki and Bi, which represent the parameters in the ticket function of the i-th amusement place.

【Output format】

An integer, indicating how much money Xiaolan needs to prepare at least, so that no matter how everyone chooses the project, he can afford it.

【Sample input】

4 2

-4 10

-2 7

【Sample output】

12

【Example description】

In the example, there are 4 people and 2 entertainment items. We use a binary group (a, b) to indicate that person a chooses the first entertainment item, and person b chooses the second entertainment item. Then there are 4 − a − Person b did not choose any item, the ticket cost corresponding to scheme (a, b) is max(−4 × a + 10, 0) × a + max(−2 × b + 7, 0) × b, all possible As follows:

spend
0 0 0
0 1 5
0 2 6
0 3 3
0 4 0
1 0 6
1 1 11
1 2 12
1 3 9
2 0 4
2 1 9
2 2 10
3 0 0
3 1

5

4 0 0

Among them, when a = 1, b = 2, the cost is the largest, which is 12. At this point 1 person goes to the first item, so

The unit price of the first item is 10 − 4 = 6, and the cost on this item is 6 × 1 = 6; 2 people go to the second item, so the unit price of the second item is 7 − 2 × 2 = 3, Spending on this project was

2 × 3 = 6; there is one person who did not go to any project, so no statistics are needed; the total cost is 12, which is the most expensive option, so the answer is 12.

[Evaluation use case scale and agreement]

For 30% of the evaluation cases, 1 ≤ N, M ≤ 10. For 50% of the evaluation cases, 1 ≤ N, M ≤ 1000. For 100% of the evaluation cases, 1 ≤ N, M, Bi ≤ 10^5, − 10^5 ≤ Ki < 0.


Test Question J: Magic Circle

Time limit: 1.0s Memory limit: 512.0MB Total score for this question: 25 points

【Problem Description】

In order to rescue her friend Xiao Q, the magician Xiaolan came to the magic circle arranged by the enemy. The magic array can be regarded as an undirected graph with N nodes and M edges, the node numbers are 0, 1, 2, . . . , N − 1, and there are no multiple edges and self-loops in the graph. The enemy has set traps on each side, and each side has a damage attribute w. Whenever Xiaolan passes by a side, he will receive the damage of w corresponding to this side. Little blue from node 0

Start, walk along the edge, want to reach the node N − 1 to rescue little Q. Xiaolan has a special magic that can be used, assuming that a path passes through the following in order

L sides: e1, e2, . . . , eL (repeated sides can appear), then the total damage Xiaolan receives during this period is

P = ∑L i=1 w(ei), w(ei) represents the damage attribute of edge ei. If L ≥ K, then Xiaolan can select K consecutive edges ec , ec+1, . The damage received, that is, the total damage of the path after using magic becomes P ′ = P − ∑c+K−1

i=cw(ei). Note that exactly K consecutive edges must be selected, so magic cannot be used when L < K. Xiaolan can only use the above magic once at most. What is the minimum damage from node 0 to node N − 1? The problem guarantees that there exists at least one path from node 0 to N − 1.

【Input format】

The first line enters three integers, N, K, M, separated by spaces. Next M lines, each line contains three integers u, v, w, which means there is an undirected edge with damage attribute w between node u and node v.

【Output format】

Output a line containing an integer, which represents the minimum damage that Xiaolan receives from node 0 to node N − 1.

【Sample input 1】

4 2 3

0 1 2

1 2 1

2 3 4

[Sample output 1]

2

【Sample input 2】

2 5 1

0 1 1

【Sample output 2】

0

【Example description】

Example 1, there is a path: 0 → 1 → 2 → 3, K = 2, if magic is used on 0 → 1 → 2, then the answer is 0 + 0 + 4 = 4; if it is used on 1 → 2 → 3 Magic, then the answer is 2 + 0 + 0 = 2. There is no answer smaller than 2, so the answer is 2. Example 2, there is a path: 0 → 1 → 0 → 1 → 0 → 1, K = 5, this path has exactly 5 edges in total, so all damage can be eliminated by magic, and the answer is 0.

[Evaluation use case scale and agreement]

For 30% of the evaluation cases, 1 ≤ N ≤ 20. For 50% of the evaluation cases, 1 ≤ N ≤ 100. For 100% of the evaluation cases, 1 ≤ N ≤ 1000, 1 ≤ M ≤ N×(N−1)/2, 1 ≤ K ≤ 10, 0 ≤ u, v ≤ N − 1, 1 ≤ w ≤ 1000.

Guess you like

Origin blog.csdn.net/lxd_max/article/details/130027392