2017 8th Java 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

Title description

A maze playground on Planet X is built on a small 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 going to the room on the left,
R means going to the room on the right,
U means going to the room on the uphill direction,
D means going to the room on 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. 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 don’t understand the rules of the game, you can refer to a simplified 4x4 maze illustration:
p1.png
Insert picture description here

Topic analysis
topic codes



The second question: 9 number formula

Title description
Observe the following formula:

9213 x 85674 = 789314562

The multiplier and the multiplicand on the left just use all the numbers from 1 to 9, each one time.
And the product happens to use all the numbers from 1 to 9, and each time is 1 time.

Please use the powerful computing power of your computer to find out how many 9-number formulas meet the above requirements?

note:

  1. The total number includes the example given in the title.
  2. The multiplier and the multiplicand are exchanged as the same plan.
    Topic analysis
    topic codes


Question 3: Status of Rubik's Cube

Title description The
second-order Rubik's Cube is a Rubik's Cube with only 2 layers, consisting of only 8 small pieces.
As shown in figure p1.png.

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 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: grid 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.

As shown in the figure: p1.png, p2.png, p3.png are feasible segmentation methods.

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
Insert picture description here
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.

public class A
{
    
    
    // a个A,b个B,c个C 字母,能组成多少个不同的长度为n的串。
    static 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 ________________________________;  //填空
    }
    
    public static void main(String[] args)
    {
    
    
        System.out.println(f(1,1,1,2));
        System.out.println(f(1,2,3,3));
    }
}

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

Note: Only fill in the missing codes in the underlined part, and do not submit any redundant content or explanatory text.
Topic analysis
topic codes



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.

public class Main
{
    
    
    static int f(String s1, String s2)
    {
    
    
        char[] c1 = s1.toCharArray();
        char[] c2 = s2.toCharArray();
        
        int[][] a = new int[c1.length+1][c2.length+1];
        
        int max = 0;
        for(int i=1; i<a.length; i++){
    
    
            for(int j=1; j<a[i].length; j++){
    
    
                if(c1[i-1]==c2[j-1]) {
    
    
                    a[i][j] = __________________;  //填空 
                    if(a[i][j] > max) max = a[i][j];
                }
            }
        }
        
        return max;
    }
    
    public static void main(String[] args){
    
    
        int n = f("abcdkkk", "baabcdadabc");
        System.out.println(n);
    }
}

Note: Only submit missing codes, do not submit existing codes and symbols. Do not submit explanatory text.
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

Please output strictly according to the requirements, and don't superfluously print the extra content like: "Please input...".

All the codes are placed in the same source file. After the debugging is passed, copy and submit the source code.
Do not use the package statement. Do not use the features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be treated as an invalid code.
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

Please output strictly according to the requirements, and don't superfluously print the extra content like: "Please input...".

All the codes are placed in the same source file. After the debugging is passed, copy and submit the source code.
Do not use the package statement. Do not use the features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be treated as an invalid code.
When submitting the program, pay attention to selecting the desired language type and compiler type.
Topic analysis
topic codes



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.

为了公平起见,小明需要从这 N 块巧克力中切出K块巧克力分给小朋友们。切出的巧克力需要满足:

1. 形状是正方形,边长是整数  
2. 大小相同  

For example, a piece of 6x5 chocolate can cut into 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

Please output strictly according to the requirements, and don't superfluously print the extra content like: "Please input...".

All the codes are placed in the same source file. After the debugging is passed, copy and submit the source code.
Do not use the package statement. Do not use the features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be treated as an invalid code.
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 rock 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 machines) <256M
CPU consumption <2000ms

Please output strictly according to the requirements, and don't superfluously print the extra content like: "Please input...".

All the codes are placed in the same source file. After the debugging is passed, copy and submit the source code.
Do not use the package statement. Do not use the features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be treated as an invalid code.
Topic analysis
topic codes



Guess you like

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