Detailed explanation of the real questions of the 9th Blue Bridge Cup JavaB Group Provincial Competition in 2018

Question to be updated

Question 1: Days

Topic description

January 1, 2000, was the first day of that year.
So, on May 4, 2000, what day was it in that year?


Note: What needs to be submitted is an integer, do not fill in any redundant content.

Question 2: Counting squares

Topic description

As shown in Figure p1.png, there are an infinite number of 1x1 small squares on a two-dimensional plane.


We draw a circle with a radius of 1000 centered on a vertex of a small square.
Can you count how many complete small squares are in this circle? 

Note: What needs to be submitted is an integer, do not fill in any redundant content.

Question 3: Complex Powers

Topic description

Let i be the imaginary unit. For any positive integer n, the real and imaginary parts of (2+3i)^n are integers.
What 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 part and the imaginary part are integers (cannot be expressed in scientific notation), no spaces are added anywhere in between, 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


Note: What needs to be submitted is a very large plural, do not fill in any redundant content.

Question 4: Number of Tests

Topic description

The inhabitants of Planet X are not very good-tempered, but fortunately, the only abnormal 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 the mobile phone must pass the drop test and be assessed a drop resistance index before it is allowed to be listed for circulation.

Planet X has a lot of towering towers that are just right for a drop test. Each floor of the tower is the same height, with a slight difference on Earth, their first floor is not the ground, but is equivalent to our 2nd floor.

If the phone is dropped from the 7th layer without breaking, but the 8th layer is broken, the phone's drop resistance index = 7.
In particular, if the phone is broken when dropped from the first layer, the drop resistance index = 0.
If the nth floor of the top floor of the tower is not broken, then the drop resistance index = n

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

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

Please fill in this maximum number of tests.

Note: What needs to be filled is an integer, do not fill in any redundant content.

Question 5: Quick Sort

Topic description

The following code can find the kth 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 the analysis 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));     } }



Note: Only submit the code that is missing from the underlined portion, do not copy any code or symbols that already exist.

Question 6: Incrementing triples

Topic description

Given three integer arrays
A = [A1, A2, ... AN], 
B = [B1, B2, ... BN], 
C = [C1, C2, ... CN],
how many do you count? triples (i, j, k) satisfy:

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

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

For 30% of the data, 1 <= N <= 100  
For 60% of the data, 1 <= N <= 1000 
For 100% of the 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

【Example of output】
27 


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


Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".
All code is placed in the same source file, after debugging, copy and submit the source code.
Don't use the package statement. Do not use features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be processed as invalid code.

Question 7: Spiral Polyline

Topic description

The spiral polyline as 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) is the length of the helical polyline segment from the origin to (X, Y).  

For example dis(0, 1)=3, dis(-2, -1)=9  

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

【Input format】
X and Y 

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

【Output format】
Output dis(X, Y)  


【Input example】
0 1

【Example of output】
3


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


Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.
Don't use the package statement. Do not use features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be processed as invalid code.

Question 8: Log Statistics

Topic description

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

ts id  

Indicates that the post with the ID number at time ts 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 considers the post to be a "hot post".  

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

Given the log, please help Xiaoming to count all the post numbers that were "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 the hot post ids in ascending order. One row per id.  

【Input example】
7 10 2  
0 1  
0 10    
10 10  
10 1  
9 1
100 3  
100 3  

【Example of output】
1  
3  

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


Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.
Don't use the package statement. Do not use features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be processed as invalid code.

Question 9: Global Warming

Topic description

You have a NxN pixel photo of a sea area, "." for ocean and "#" for land, like this:

.......
.##....
.##....
....##.
..####.
...###.
.......

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

Due to rising sea levels caused by global warming, scientists predict that a pixel of the edge of the island will be submerged by sea water in the next few decades. Specifically, if a land pixel is adjacent to an ocean (there are oceans in four adjacent pixels up, down, left, and right), it will be submerged.  

For example, the sea area in the picture above will look like this in the future:

.......
.......
.......
.......
....#..
.......
.......

Please count: According to scientists' predictions, 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 photo guarantees that the pixels in row 1, column 1, row N, and column N are all oceans.  

[Output format]
An integer represents the answer.

【Input example】

.......
.##....
.##....
....##.
..####.
...###.
.. .....  

【Example of output】
1  

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


Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.
Don't use the package statement. Do not use features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be processed as invalid code.

Question 10: Counting of Heaps

Topic description

We know that a heap with N elements can be viewed as a complete binary tree with 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 stacks there are?  

For example, for N=4, there are the following 3 types:

    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 the data, 1 <= N <= 1000  
For 70% of the data, 1 <= N <= 10000  
For 100% of the data, 1 <= N <= 100000

[Output format]
An integer represents the answer.  

【Input example】
4  

【Example of output】
3


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


Please output strictly according to the requirements, and do not superficially print superfluous content like: "Please enter...".

All code is placed in the same source file, after debugging, copy and submit the source code.
Don't use the package statement. Do not use features of jdk1.7 and above.
The name of the main class must be: Main, otherwise it will be processed as invalid code.
 

 

 

 

 

Guess you like

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