2017 4th C/C++ Group A Blue Bridge Cup Provincial Competition Real Questions

Here is the topic column of the Blue Bridge Cup over the years. It will be updated and will release the real questions and answers from previous years. Welcome friends to pay attention to me. Your likes and attention are the best motivation for me! ! !
Update one real question every day, so stay tuned

Lanqiao Cup Past Papers and Detailed Answers


Question 1: Maze

The title describes
a maze playground on Planet X built on a hillside.

It is composed of 10x10 interconnected small rooms.

There is a big letter written on the floor of the room.

We assume that the player is standing facing uphill, then:

L means go to the room on the left,

R means go to the room on the right,

U means go to the room uphill,

D means going to the room downhill.

The inhabitants of Planet X are a bit lazy and don't want to think hard.

They prefer to play games of luck. The same is true for this game!

At the beginning, the helicopter put 100 players into small rooms.

The player must move according to the letters on the ground.

The maze map is as follows:


UDDLUULRUL

UURLLLRRRU

RRUURLDLRD

RUDDDDUUUU

URUDLLRRUU

DURLRLDLRL

ULLURLLRDU

RDLULLRDDD

UUDDUDUDLL

ULRDLUURRR


Please calculate, in the end, how many players will get out of the maze?

Instead of going around in circles.

Please submit the whole number to indicate the number of players who walked out of the maze. Do not fill in any extra content.

If you still don’t understand the rules of the game, you can refer to a simplified 4x4 maze illustration:
Insert picture description here

Topic analysis
topic codes



Question 2: Jumping the grasshopper

Title description
There are 9 plates arranged in a circle.

Eight of the plates contained eight grasshoppers, and one of them was empty.

We number these grasshoppers clockwise as 1~8

Each grasshopper can jump to the adjacent empty plate,

You can also use a little more force to jump over an adjacent grasshopper into the empty plate.

Please calculate, if you want to make the formation of the grasshoppers to be arranged counterclockwise,

And keep the position of the empty disk unchanged (that is, 1-8 transposition, 2-7 transposition,...), how many jumps do you have to go through at least?

Note: The required submission is an integer, please do not fill in any redundant content or explanatory text.
Insert picture description here

Topic analysis
topic codes



The third question: Rubik's cube simulation

Title description The
second-order Rubik's Cube is a Rubik's Cube with only 2 layers, consisting of only 8 small pieces.

Xiao Ming is very naughty. He only likes 3 colors, so he repainted the second-order Rubik's Cube at home, as follows:

Front: orange

Right: Green

Above: yellow

Left: green

Below: orange

Back: yellow

Please calculate how many different states there are after such a Rubik's Cube is disrupted.

If the two states after the overall rotation of the Rubik's Cube, the colors of all sides are the same, it is considered the same state.

Please submit an integer representing the number of states, and do not fill in any redundant content or explanatory text.
Insert picture description here

Topic analysis
topic codes



Fourth question: block division

The title describes a
6x6 grid, cut into two parts along the edge of the grid.
The shapes of the two parts are required to be exactly the same.
Figure 4-1, 4-2, 4-3: This is a feasible method of segmentation.
Try to calculate:
Including these three division methods, how many different division methods are there in total?
Note: Rotational symmetry belongs to the same division method.
Please submit the whole number, do not fill in any extra content or explanatory text.
Insert picture description here

Topic analysis
topic codes



Question 5: Letter string

Title description
The three letters A, B, and C can form many strings.
For example: "A", "AB", "ABC", "ABA", "AACBB"…

Now, Xiao Ming is thinking about a question:
If the number of each letter is limited, how many strings of known length can be formed?

He asked a good friend to help, and quickly got the code. The
solution was super simple, but the most important part was unclear.

Please carefully analyze the source code and fill in the missing content in the underlined part.

#include <stdio.h>

// a个A,b个B,c个C 字母,能组成多少个不同的长度为n的串。
int f(int a, int b, int c, int n)
{
    
    
    if(a<0 || b<0 || c<0) return 0;
    if(n==0) return 1; 
    
    return ______________________________________ ;  // 填空
}

int main()
{
    
    
    printf("%d\n", f(1,1,1,2));
    printf("%d\n", f(1,2,3,3));
    return 0;
}

For the above test data, the result of Xiaoming's oral calculation should be:
6
19er
problem analysis
problem code



Question 6: The largest common substring

Title description The problem of the
maximum common substring length is: what
is the maximum length that can be matched among all substrings of two strings.

For example: "abcdkkk" and "baabcdadabc",
the longest common substring that can be found is "abcd", so the maximum common substring length is 4.

The following program is solved by the matrix method, which is a relatively effective solution for the case where the string size is not large.

Please analyze the idea of ​​the solution and fill in the missing code in the underlined part.
Topic analysis
topic codes



Seventh question: regular problems

Title description
Consider a simple regular expression: a regular expression
consisting only of x () |.
Xiao Ming wants to find the length of the longest string that this regular expression can accept.

For example, ((xx|xxx)x|(x|xx))xx can accept the longest character string: xxxxxx, the length is 6.

enter

A regular expression consisting of x()|. The input length does not exceed 100, and it is legal.

Output

The length of the longest string that this regular expression can accept.

For example,
enter:
((xx|xxx)x|(x|xx))xx

The program should output:
6

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 8: Buns make up the number

Title description
Xiao Ming eats breakfast at a bun shop almost every morning. He found that this steamed bun was shopped with N kinds of steamers, of which the i-th steamer could hold Ai buns. Each kind of steamer has a lot of baskets, which can be regarded as infinite baskets.

Whenever a customer wants to buy X steamed buns, the uncle who sells steamed buns will quickly select a number of steamed steamed buns, so that there are exactly X steamed steamed buns in these several cages. For example, there are 3 kinds of steamers, which can hold 3, 4, and 5 buns.

When a customer wants to buy 11 buns, the uncle will choose 2 cages of 3 plus 1 cage of 5 (or maybe 1 cage of 3 plus 2 cages of 4).

Of course, sometimes Uncle Baozi can't make up the amount the customer wants to buy. For example, there are 3 kinds of steamers, which can hold 4, 5, and 6 buns. When the customer wanted to buy 7 buns, the uncle couldn't get it together.

Xiao Ming wanted to know how many kinds of numbers Uncle Bao could not make up.

enter

The first line contains an integer N. (1 <= N <= 100)
Each of the following N lines contains an integer Ai. (1 <= Ai <= 100)

Output

An integer represents the answer. If the number that cannot be made up is infinite, output INF.

For example,
enter:
2
4
5

The program should output:
6

For another example,
enter:
2
4
6

The program should output:
INF

Sample explanation:
For sample 1, the unfinished numbers include: 1, 2, 3, 6, 7, 11.
For example 2, all odd numbers cannot be made up, so there are infinitely many.

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms
topic analysis
topic code



Question 9: Divide Chocolate

Topic description On
Children's Day, K children visited Xiao Ming's house. Xiao Ming took out a collection of chocolates to entertain the children.
Xiao Ming has N pieces of chocolate in total, of which the i-th piece is a rectangle composed of Hi x Wi squares.

To be fair, Xiao Ming needs to cut out K pieces of chocolate from the N pieces of chocolate to share with the children. The cut chocolate needs to meet:

  1. The shape is square and the side length is an integer
  2. Same size

For example, a piece of 6x5 chocolate can cut 6 pieces of 2x2 chocolate or 2 pieces of 3x3 chocolate.

Of course, the kids all hope that the chocolate they get is as big as possible. Can you help Little Hi calculate the maximum side length?

Input The
first line contains two integers N and K. (1 <= N, K <= 100000)
Each of the following N lines contains two integers Hi and Wi. (1 <= Hi, Wi <= 100000)
Enter to ensure that each child can get at least a 1x1 chocolate.

Output
Output the maximum possible side length of the cut square chocolate.

Sample input:
2 10
6 5
5 6

Sample output:
2

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

Topic analysis
topic codes



Question 10: Paint area

The title describes that
a group of archeological robots on Planet X are doing archeology on a ruin.
The ground in this area is as hard as stone and flat as a mirror.
The management staff has established a standard rectangular coordinate system for convenience.

Each robot has its own specialties and unique skills. They are also interested in different content.
After various measurements, each robot will report one or more rectangular areas as priority archaeological areas.

The format of the rectangle is (x1, y1, x2, y2), which represents the coordinates of the two diagonal points of the rectangle.

In order to be eye-catching, the headquarters requested that all the rectangular areas selected by the robots be painted with yellow paint.
Xiao Ming doesn't need to be a painter, but he needs to calculate how much paint will be consumed.

In fact, this is not difficult, as long as the total area covered by all rectangles is calculated.
Note that the rectangles may overlap.

The input of this question is a number of rectangles, and the total area covered by them is required to be output.

Input format: the
first line, an integer n, indicates how many rectangles (1<=n<10000) there are in the
next n lines, each line has 4 integers x1 y1 x2 y2, separated by spaces, indicating two pairs of rectangles The corner vertex coordinates.
(0<= x1,y1,x2,y2 <=10000)

Output format:
one integer per line, representing the total area covered by the rectangle.

For example,
enter:
3
1 5 10 10
3 1 20 20
2 7 15 17

The program should output:
340

For another example,
enter:
3
5 2 10 6
2 7 12 10
8 1 15 15

The program should output:
128

Resource agreement:
peak memory consumption (including virtual machine) <256M
CPU consumption <2000ms
question analysis
question code



Guess you like

Origin blog.csdn.net/kiwi_berrys/article/details/111462986