The 4th C/C++ Group A Blue Bridge Cup Provincial Competition in 2017

Here is the topic column of the Blue Bridge Cup over the years. It will be updated successively and the real questions and answers of previous years will be released. I welcome you to follow me. Your likes and attention are the best motivation for me! ! !
The real questions are updated every day, so stay tuned

Blue Bridge Cup real questions and detailed answers over the years


Question 1: Maze

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

It consists of 10x10 interconnected small rooms.

A large letter was 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 to go to the room in the uphill direction,

D means going to the room in the downhill direction.

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

They prefer to play games of luck. So is this game!

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

Players 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?

rather than going around in circles.

Please submit this integer to indicate the number of players who walked out of the maze, and do not fill in any superfluous content.

If you don't understand the rules of the game, here is a simplified illustration of a 4x4 maze:
insert image description here

topic analysis
topic code



Question 2: Jumping Grasshoppers

Item Description
There are 9 plates arranged in a circle.

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

We number these grasshoppers clockwise from 1 to 8

Each grasshopper can jump to the adjacent empty plate,

You can also use a little more force and jump over an adjacent grasshopper into an 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 (ie 1-8 transposition, 2-7 transposition, ...), at least how many jumps should it go through?

Note: The required submission is an integer, please do not fill in any extra content or explanatory text.
insert image description here

topic analysis
topic code



Question 3: Rubik's Cube Simulation

Title description
The second-order Rubik's Cube is a Rubik's Cube with only 2 layers and consists 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

top: 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 have the same color on each surface after the overall rotation of the Rubik's cube, they are considered to be the same state.

Please submit an integer representing the number of states without any extra or explanatory text.
insert image description here

topic analysis
topic code



Question 4: Block Division

Problem Description
A 6x6 grid, cut in two along the sides of the grid.
The two parts are required to be exactly the same shape.
As shown in Figure 4-1, 4-2, 4-3: It is a feasible segmentation method.
Try to calculate:
Including these three division methods, how many different division methods are there in total.
Note: Rotational symmetry belongs to the same segmentation method.
Please submit this integer without any superfluous content or explanatory text.
insert image description here

topic analysis
topic code



Question 5: Alphabet Strings

Description of the topic
Many strings can be formed from the three letters A, B, and C.
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 got the code quickly, the
solution was super simple, but the most important part was vague.

Please analyze the source code carefully 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
question analysis
question code



Question 6: Maximum Common Substring

Topic description The
maximum common substring length problem is to
find the maximum length of all substrings of two strings that can be matched.

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 more effective solution for the case where the size of the string is not large.

Please analyze the idea of ​​this solution and complete the missing code in the underlined part.
topic analysis
topic code



Question 7: Regular Questions

Topic 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 The longest string that can be accepted is: xxxxxx, the length is 6.

enter

A regular expression consisting of x()|. The input length does not exceed 100, which is guaranteed to be legal.

output

The length of the longest string accepted by this regular expression.

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

The program should output:
6

Resource convention:
peak memory consumption (including virtual machine) < 256M
CPU consumption < 1000ms

topic analysis
topic code



Question 8: Buns make up the number

Title Description
Xiao Ming eats breakfast at a steamed bun shop almost every morning. He found that this steamed bun shop has N kinds of steamers, and the i-th steamer can hold Ai buns exactly. Each type of steamer has a very large number of cages, which can be considered as infinite cages.

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

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

Of course, sometimes Uncle Baozi can't make up the quantity that customers want to buy anyway. For example, there are 3 types of steamers, which can hold 4, 5 and 6 buns respectively. And when the customer wanted to buy 7 buns, the uncle couldn't come out.

Xiao Ming wanted to know how many kinds of numbers there were that Uncle Baozi couldn't figure out.

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 representing the answer. If there are infinite numbers that cannot be made up, 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

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

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



Question 9: Dividing Chocolate

Title Description
K children visited Xiaoming's house on Children's Day. Xiao Ming took out a collection of chocolates to entertain the children.
Xiao Ming has a total of N pieces of chocolate, 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 these N pieces of chocolate and distribute them to the children. The cut chocolate needs to meet:

  1. The shape is a square and the side lengths are integers
  2. same size

For example, a 6x5 chocolate can be cut into 6 2x2 chocolates or 2 3x3 chocolates.

Of course, the children all want the chocolate to be as large as possible. Can you help Xiao 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)
The input guarantees that each child will get at least one 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 convention:
peak memory consumption (including virtual machine) < 256M
CPU consumption < 1000ms

topic analysis
topic code



Question 10: Paint Area

The title describes
that a group of archaeological robots from Planet X are doing archaeology on the ruins.
The ground in this area is as hard as a rock and as smooth as a mirror.
Managers have established a standard Cartesian coordinate system for convenience.

Each robot has its own specialties and unique skills. Their interests are also different.
After various measurements, each robot reports one or more rectangular areas as areas of priority for archaeology.

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

In order to stand out, the headquarters requires that all robot-selected rectangular areas be painted yellow.
Xiao Ming doesn't need to be a painter, but he needs to calculate how much paint it will cost.

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

The input of this problem 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, indicating how many rectangles there are (1<=n<10000)
The next n lines, each line has 4 integers x1 y1 x2 y2, separated by spaces, indicating two pairs of rectangles 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 convention:
peak memory consumption (including virtual machine) < 256M
CPU consumption < 2000ms
topic analysis
topic code



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324660331&siteId=291194637