2018 9th Java Group B 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: The first few days

The title describes
January 1, 2000, which is the first day of that year.
So, on May 4th, 2000, which day was that year?

Note: What needs to be submitted is an integer, do not fill in any extra content.
Topic analysis
topic codes



Question 2: Counting squares

Title description
As shown in figure p1.png, there are countless 1x1 small squares on the two-dimensional plane.
Insert picture description here
We draw a circle with a radius of 1000 with a vertex of a small square as the center.
Can you calculate how many complete small squares are in this circle?
Topic analysis
topic codes



The third question: complex number power

Title description
Let i be the imaginary unit. For any positive integer n, the real and imaginary parts of (2+3i)^n are both integers.
How much is (2+3i)^123456 equal to? That is (2+3i) to the power of 123456. This number is very large and requires accurate representation.

The answer is written in the form of "real part ± imaginary part i". The real and imaginary parts are both integers (cannot be expressed in scientific notation), no spaces are added anywhere in the middle, and no positive sign is added before the real part is positive. (2+3i)^2 is written as: -5+12i,
(2+3i)^5 is written as: 122-597i
question analysis
question code



Question 4: Number of tests

The title describes
that the residents of Planet X have a bad temper, but fortunately, the only unusual behavior when they are angry is to drop their mobile phones.
Major manufacturers have also launched a variety of drop-resistant mobile phones. The Quality Supervision Bureau of Planet X stipulates that mobile phones must undergo a drop resistance test, and a drop resistance index has been assessed before they are allowed to be marketed.

Planet X has many towering towers that can be used for fall resistance tests. The height of each floor of the tower is the same. What is slightly different from the earth is that their first floor is not the ground, but is equivalent to our second floor.

If the phone is thrown from the 7th layer and it is not broken, but the 8th layer is broken, the mobile phone withstand index=7.
In particular, if the mobile phone breaks when dropped from the first layer, the drop resistance index=0.
If the nth floor of the highest floor of the tower is not broken, then the drop resistance index = n

In order to reduce the number of tests, sample 3 mobile phones from each manufacturer to participate in the test.

The tower height of a certain test is 1000 floors. If we always adopt the best strategy, how many times do we need to test at most to determine the phone's drop resistance index under the worst luck?

Please fill in this maximum number of tests.
Topic analysis
topic codes



Question 5: Quick Sort

Title description The
following code can find the k-th smallest element from the array a[].
It uses a divide-and-conquer algorithm similar to quicksort, and the expected time complexity is O(N).
Please read and analyze the source code carefully, and fill in the missing content in the underlined part.

import java.util.Random;
public class Main{
    
    
public static int quickSelect(int a[], int l, int r, int k) {
    
    
Random rand = new Random();
int p = rand.nextInt(r - l + 1) + l;
int x = a[p];
int tmp = a[p]; a[p] = a[r]; a[r] = tmp;
int i = l, j = r;
while(i < j) {
    
    
                while(i < j && a[i] < x) i++;
                if(i < j) {
    
    
                        a[j] = a[i];
                        j--;
                }
                while(i < j && a[j] > x) j--;
                if(i < j) {
    
    
                        a[i] = a[j];
                        i++;
                }
        }
        a[i] = x;
        p = i;
        if(i - l + 1 == k) return a[i];
        if(i - l + 1 < k) return quickSelect( _________________________________ ); //填空
        else return quickSelect(a, l, i - 1, k);
}
public static void main(String args[]) {
    
    
int [] a = {
    
    1, 4, 2, 8, 5, 7};
System.out.println(quickSelect(a, 0, 5, 4));
}
}

Topic analysis
topic codes



Question 6: Incremental triples

Title description
Given three integer arrays
A = [A1, A2,… AN],
B = [B1, B2,… BN],
C = [C1, C2,… CN],
please count how many triples there are (i, j, k) satisfies:

  1. 1 <= i, j, k <= N
  2. Ai < Bj < Ck

[Input format] The
first line contains an integer N.
The second line contains N integers A1, A2,… AN.
The third line contains N integers B1, B2,… BN.
The fourth line contains N integers C1, C2,… CN.

For 30% data, 1 <= N <= 100
For 60% data, 1 <= N <= 1000
For 100% data, 1 <= N <= 100000 0 <= Ai, Bi, Ci <= 100000

[Output format]
An integer represents the answer

[Input example]
3
1 1 1
2 2 2
3 3 3

【Sample output】
27

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



Question 7: Spiral Polyline

Title description
The spiral broken line shown in Figure p1.pgn passes through all the whole points on the plane exactly once.
For the whole point (X, Y), we define its distance to the origin dis(X, Y) to be the length of the spiral polyline segment from the origin to (X, Y).
Insert picture description here
For example, dis(0, 1)=3, dis(-2, -1)=9

Given the whole point coordinates (X, Y), can you calculate dis(X, Y)?

[Input format]
X and Y

For 40% data, -1000 <= X, Y <= 1000
For 70% data, -100,000 <= X, Y <= 100000
For 100% data, -1000000000 <= X, Y <= 1000000000

[Output format]
output dis(X, Y)

【Input example】
0 1

[Sample output]

3

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



Question 8: Log Statistics

Title description
Xiao Ming maintains a programmers forum. Now he has collected a "like" log with N lines in total. The format of each line is:

ts id

Indicates that the post numbered id at ts time received a "like".

Now Xiao Ming wants to count which posts were once "hot posts". If a post has received no less than K likes in any time period of length D, Xiao Ming thinks that the post was once a "hot post".

Specifically, if there is a certain moment T that satisfies that the post receives no less than K likes during the period of [T, T+D) (note that the left is closed and the right is open), the post was once "hot Post".

Given a log, please help Xiao Ming count all the post numbers that were once "hot posts".

[Input format] The
first line contains three integers N, D and K.
The following N lines have one log per line, containing two integers ts and id.

For 50% of the data, 1 <= K <= N <= 1000
For 100% of the data, 1 <= K <= N <= 100000 0 <= ts <= 100000 0 <= id <= 100000

[Output format]
Output hot post IDs in ascending order. One line per id.

[Input example]
7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3

[Sample output]
1
3

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

Topic analysis
topic codes



Question 9: Global Warming

Title description
You have a picture of a certain sea area with NxN pixels, "." means ocean, "#" means land, as shown below:


.##…
.##…
…##.
…####.
…###.

Among them, a piece of land connected in four directions "up, down, left, and right" forms an island. For example, there are 2 islands in the picture above.

As global warming has caused the sea to rise, scientists predict that in the next few decades, a pixel area on the edge of the island will be submerged by sea water. Specifically, if a land pixel is adjacent to the ocean (there is an ocean among the four adjacent pixels up, down, left, and right), it will be submerged.

For example, the sea area in the above picture will become as follows in the future:





…#…

Please calculate: According to the prediction of scientists, how many islands in the photo will be completely submerged.

[Input format] The
first line contains an integer N. (1 <= N <= 1000) The
following N rows and N columns represent a sea area photo.

The picture guarantees that the pixels in the first row, the first column, the Nth row, and the Nth column are all oceans.

[Output format]
An integer represents the answer.

[Input example]
7

.##…
.##…
…##.
…####.
…###.

[Sample output]
1

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



Tenth question: heap count

Title description
We know that a heap containing N elements can be regarded as a complete binary tree containing N nodes.
Each node has a weight. For a small root heap, the weight of the parent node must be less than the weight of its child nodes.

Assuming that the weights of N nodes are 1~N, can you find out how many different root piles there are?

For example, for N=4, there are three types as follows:

    1
   / \
  2   3
 /
4

    1
   / \
  3   2
 /
4

    1
   / \
  2   4
 /
3

Since the number may exceed the integer range, you only need to output the remainder of dividing the result by 1000000009.

[Input format]
An integer N.
For 40% of data, 1 <= N <= 1000
For 70% of data, 1 <= N <= 10000
For 100% of data, 1 <= N <= 100000

[Output format]
An integer represents the answer.

【Input example】
4

[Sample output]
3

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



Guess you like

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