2013 4th 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: Week at the end of the century

Title description
There was a cult that claimed that December 31, 1999 was the end of the world. Of course, the rumor is self-defeating. Some people say that December 31st at the end of a certain century in the future, if it is Monday, it will...
Interestingly, December 31st in any year at the end of the century cannot be Monday!! So, "rumor maker" Modified to Sunday again... December 31st in 1999 is a Friday. May I ask: Which one of the nearest centuries in the future (ie xx99) will happen to be Sunday (ie Sunday) on December 31st?
Please answer the Year (only write this four integers, do not write extra information Dec. 31, etc.)
subject analysis
entitled Code



Question 2: The sloppy formula

Title description
Xiao Ming is impatient. When he was in elementary school, he often copied the questions his teacher wrote on the blackboard wrong. Once, the teacher asked the question: 36 x 495 =? He copied it as: 396 x 45 =? But the result was dramatic, and his answer turned out to be correct! ! Because 36 * 495 = 396 * 45 = 17820 There may be many coincidences like this, such as: 27 * 594 = 297 * 54 Assuming that abcde represents 5 different numbers from 1 to 9 (note that they are different numbers, and Does not contain 0) How many kinds of expressions can satisfy the form: ab * cde = adb * ce? Please use the advantages of computers to find all the possibilities and answer the types and numbers of different calculations. Formulas that satisfy the commutative law of multiplication are counted as different types, so the answer must be an even number.
The answer is submitted directly through the browser.
Note: Only submit a number representing the final statistical category, do not submit the answering process or other redundant content.
Topic analysis
topic codes



Question 3: Revitalizing China

Topic description
Xiao Ming participated in the school's fun sports meet, one of which is: jumping grid. There are some grids drawn on the ground, and a word is written in each grid, as shown below: (also see p1.jpg)

Starting from me, starting from me, starting
from revitalizing,
starting from revitalizing,
starting from revitalizing the Chinese
competition, first stand in the upper left corner of the grid with the word "from", you can jump horizontally or vertically to the adjacent grid, but you can't jump Go to the diagonal grid or other location. Always jump to the end of the word "华". The route requested to be skipped just constitutes the phrase "starting from me to revitalize China."
Please help Xiaoming calculate how many possible jumping routes he has?
Insert picture description here

The answer is an integer, please submit the number directly through the browser.
Note: Do not submit the answering process or other supporting explanation content.
Topic analysis
topic codes



Fourth question: Golden consecutive points

Title description The
golden ratio 0.61803... is an irrational number. This constant is very important and will appear in many engineering problems. Sometimes it is necessary to find this number very accurately. For some precision engineering, the accuracy of the constant is very important. Maybe you’ve heard of the Hubble Space Telescope. After it first lifted off, it found an artificial processing error. For such a behemoth, it was actually an error many times thinner than a hair in the mirror processing. It has become "myopia"!!
Closer to home, how do we find the golden ratio as accurate as possible? There are many ways. The simpler one is to use continued fractions:

              1
黄金数 = ---------------------
                    1
         1 + -----------------
                      1
             1 + -------------
                        1
                 1 + ---------
                      1 + ...

The more "layers" the continued fraction is calculated, the closer its value is to the golden ratio. Please use this feature to find a sufficiently accurate value of the golden ratio, requiring rounding to 100 digits after the decimal point.
The value of 3 digits after the decimal point: 0.618 The value
of 4 digits after the decimal point: 0.6180 The value
of 5 digits after the decimal point : 0.61803 The value
of 7 digits after the decimal point: 0.6180340
(note the trailing 0, can not be ignored)
Your task is: Write the golden ratio value with accuracy to 100 digits after the decimal point.
Note: the mantissa is rounded off! Keep the mantissa 0!
Obviously the answer is a decimal with 100 digits after the decimal point. Please submit the number directly through the browser.
Note: Do not submit the answering process or other supporting explanation content.

Topic analysis
topic codes



Fifth question: rational numbers

Title description A
rational number is a number that can be expressed as the ratio of two integers. In general, we use approximate decimals. But sometimes, errors are not allowed and two integers must be used to represent a rational number.
At this time, we can create a "rational number class", the following code initially achieves this goal. For brevity, it only provides addition and multiplication operations.

class Rational
{
    
    
    private long ra;
    private long rb;
    
    private long gcd(long a, long b){
    
    
        if(b==0) return a;
        return gcd(b,a%b);
    }
    public Rational(long a, long b){
    
    
        ra = a;
        rb = b;    
        long k = gcd(ra,rb);
        if(k>1){
    
     //需要约分
            ra /= k;  
            rb /= k;
        }
    }
    // 加法
    public Rational add(Rational x){
    
    
        return ________________________________________;  //填空位置
    }
    // 乘法
    public Rational mul(Rational x){
    
    
        return new Rational(ra*x.ra, rb*x.rb);
    }
    public String toString(){
    
    
        if(rb==1) return "" + ra;
        return ra + "/" + rb;
    }
}
 
使用该类的示例:
    Rational a = new Rational(1,3);
    Rational b = new Rational(1,6);
    Rational c = a.add(b);
    System.out.println(a + "+" + b + "=" + c);

Topic analysis
topic codes



Sixth question: Three parts order

Title description
There are many classic algorithms for general sorting, such as quick sorting, hill sorting, etc.
But in actual application, there are often more or less special requirements. We don't need to apply those classic algorithms, we can build better solutions based on the actual situation.
For example, sort and sort the numbers in an integer array:
make all negative numbers to the left, positive numbers to the right, and 0 in the middle. Note that the characteristic of the problem is that order is not required in the negative and positive areas. You can use this feature to end the battle with one linear scan!! The
following program has achieved this goal.

    static void sort(int[] x)
    {
    
    
        int p = 0;
        int left = 0;
        int right = x.length-1;
        
        while(p<=right){
    
    
            if(x[p]<0){
    
    
                int t = x[left];
                x[left] = x[p];
                x[p] = t;
                left++;
                p++;
            }
            else if(x[p]>0){
    
    
                int t = x[right];
                x[right] = x[p];
                x[p] = t;
                right--;            
            }
            else{
    
    
                _________________________;  //代码填空位置
            }
        }
    }

If an array is given:
25,18,-2,0,16,-5,33,21,0,19,-16,25,-3,0
, after sorting:
-3,-2,-16, -5,0,0,0,21,19,33,25,16,18,25
topic analysis
topic code



Question 7: Wrong ticket

Title description A
certain secret-related unit issued a certain kind of bill, and it must be recovered at the end of the year.
Each ticket has a unique ID number. The ID numbers of all bills throughout the year are consecutive, but the starting number of the ID is randomly selected.
Due to the negligence of the staff, an error occurred when entering the ID number, which caused one ID to be out of number and another to be duplicated.
Your task is to find out the ID of the broken number and the ID of the repeated number through programming.
Assume that a broken number cannot occur between the largest and smallest numbers.
The program is required to first input an integer N (N<100) to indicate the number of data rows.
Then read in N rows of data.
The length of each line of data varies, and is a number (not more than 100) positive integers (not more than 100000) separated by spaces.
Each integer represents an ID number.

The program is required to output one line, containing two integers mn, separated by spaces.
Among them, m represents the broken ID, n represents the repeated ID

For example:
user input:
2
5 6 8 11 9
10 12 9

The program output:
7 9

Another example:
user input:
6
164 178 108 109 180 155 141 159 104 182 179 118 137 184 115 124 125 129 168 196
172 189 127 107 112 192 103 131 133 169 158
128 102 110 148 139 157 140 195 197
185 152 135 106 123 173 122 136 174 191 145 116 151 143 175 120 161 134 162 190
149 138 142 146 199 126 165 156 153 193 144 166 170 121 171 132 101 194 187 188
113 130 176 154 177 120 117 150 114 183 186 181 100 163 160 167 147 198 111 119

The program output:
105 120

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



Question 8: Lucky Number

Title description The
lucky number was named by the Polish mathematician Ulam. It is generated using a "sieve method" similar to the generation of prime numbers.
First, write the natural numbers 1, 2, 3, 4, 5, 6,...
1 is the first lucky number.
We start with the number 2. Delete all items whose serial numbers can be divisible by 2 and become:
1 _ 3 _ 5 _ 7 _ 9 …shrink them and reorder them to:
1 3 5 7 9…. At this time, 3 is the second lucky number, and then all the numbers in the sequence number position that can be divisible by 3 are deleted. Note that it is the position of the serial number, not whether the number itself is divisible by 3!! The deleted number should be 5, 11, 17,…
at this time 7 is the third lucky number, and then delete the position of the serial number that is divisible by 7 ( 19,39,...) The
last remaining sequence is similar:
1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75 , 79, …
This question requires:
Enter two positive integers mn, separated by spaces (m <n <1000*1000) The
program outputs the number of lucky numbers between m and n (not including m and n).

For example:
user input:
1 20
program output:
5

For example:
user input:
30 69
program output:
8

Resource agreement:
peak memory consumption (including virtual machines) <64M
CPU consumption <2000ms

Topic analysis
topic codes



Question 9: Mixed numbers

The title description
100 can be expressed as a mixed number: 100 = 3 + 69258/714
can also be expressed as: 100 = 82 + 3546/197
Note feature: In a mixed number, the numbers 1~9 appear separately and only once (not including 0).
There are 11 representations of 100 for mixed numbers like this.
Question requirements:
read a positive integer N (N<1000*1000) from the standard input and the
program outputs the number with numbers 1~9 without repeating and not missing all the numbers represented by the mixed number.
Note: It is not required to output every representation, only count how many representations there are!
For example:
user input:
100
program output:
11
another example:
user input:
105
program output:
6
resource convention:
peak memory consumption (including virtual machine) <64M
CPU consumption <3000ms
title analysis
title code



Question 10: Number of consecutive intervals

Title description
Xiao Ming has been thinking about such a strange and interesting question these days:
how many consecutive intervals are there in a full array of 1~N? The definition of the consecutive interval mentioned here is:
if all the elements in the interval [L, R] (that is, the Lth to Rth elements of this arrangement) are sorted ascendingly, a length of R-L+1 can be obtained The "continuous" sequence is called this interval consecutive number interval.
When N is very small, Xiao Ming can quickly calculate the answer, but when N becomes large, the problem is not that simple. Now Xiao Ming needs your help.
Input format: The
first line is a positive integer N (1 <= N <= 50000), which represents the scale of the full array.
The second line is N different numbers Pi (1 <= Pi <= N), which represents a certain permutation of these N numbers.
Output format:
output an integer, indicating the number of different consecutive intervals.
Example:
User input:
4
3 2 4 1 The
program should output:
7
User input:
5
3 4 2 5 1 The
program should output:
9
Explanation: In the
first use case, there are 7 consecutive intervals: [1,1 ], [1,2], [1,3], [1,4], [2,2], [3,3], [4,4] In the
second use case, there are 9 consecutive intervals respectively Yes: [1,1], [1,2], [1,3], [1,4], [1,5], [2,2], [3,3], [4,4], [5,5]

Resource agreement:
peak memory consumption (including virtual machines) <64M
CPU consumption <5000ms
question analysis
question code



Guess you like

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