The 4th Java Group B Blue Bridge Cup Provincial Competition in 2013

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

Title Description
There was a cult that December 31, 1999 was the end of the world. Of course, the rumor has been subverted. It is also said that December 31st at the end of the century in the future, if it is a Monday...
Interestingly, December 31st in any end of the century year cannot be a Monday!! So, "rumor maker" Modified to Sunday again... December 31st in 1999 is Friday. May I ask: Which of the next century-end years (ie xx99) will be on Sunday (ie Sunday) on December 31st in the future?
Please answer the year (only write this 4-digit integer, do not write extra information such as December 31)
topic analysis
topic code



Question 2: Sloppy Calculations

Description of the topic
Xiao Ming is an impatient person. When he was in elementary school, he often copied the topics written by the teacher on the blackboard by mistake. Once, the teacher asked the question: 36 x 495 = ? He copied it: 396 x 45 = ? But the result was dramatic, his answer turned out to be right! ! Because 36 * 495 = 396 * 45 = 17820 There may be many coincidences like this, for example: 27 * 594 = 297 * 54 Suppose abcde represents 5 different numbers from 1 to 9 (note that they are different numbers, and Excluding 0) How many formulas can there be in the form: ab * cde = adb * ce? Please use the advantages of computer to find all the possibilities and answer the number of types of different calculations. Expressions that satisfy the commutative law of multiplication count as different kinds, so the answer must be an even number.
Answers are submitted directly through the browser.
Note: Only submit a number indicating the final number of statistical categories, do not submit the solution process or other superfluous content.
topic analysis
topic code



Topic 3: Revitalize China

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

Starting from me to
revitalize
, starting to revitalize China,
starting the revitalization of China
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 cannot jump to a diagonal grid or other location. Have to skip to the end of the word "Hua". The route to be skipped is exactly what constitutes the phrase "start from me to revitalize China".
Could you please help Xiao Ming to calculate how many possible jumping routes he has?
insert image description here

The answer is an integer, please submit the number directly through your browser.
Note: Do not submit a solution process, or other explanatory content.
topic analysis
topic code



Question 4: Golden Consecutive Fractions

Problem Description
The golden ratio 0.61803… is an irrational number. This constant is very important and appears in many engineering problems. Sometimes it is necessary to get this number very precise. For some precision engineering, the precision of the constants is important. Maybe you have heard of the Hubble Space Telescope, which discovered a manual processing error after its first lift-off. For such a behemoth, it is actually just a mistake in the mirror processing that is many times thinner than a human hair. It became "myopia"!!
Closer to home, how do we get the most accurate value of the golden ratio possible? There are many ways. A simpler one is to use continued fractions:

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

The more "layers" this continuous fraction is calculated, the closer its value is to the golden ratio. Please take advantage of this feature to find a sufficiently accurate value for the golden ratio, requiring rounding to 100 decimal places.
The value of 3 decimal places is: 0.618 The value
of 4 decimal places is: 0.6180
The value of 5 decimal places is: 0.61803 The value
of 7 decimal places is: 0.6180340
(note the trailing 0, which cannot be ignored)
Your task is: Write the golden section value to 100 decimal places of precision.
Note: Rounding of the mantissa! If the mantissa is 0, keep it!
Obviously the answer is a decimal with 100 digits after the decimal point, please submit that number directly through your browser.
Note: Do not submit a solution process, or other explanatory content.

topic analysis
topic code



Question 5: Class of Rational Numbers

Problem Description
A rational number is a number that can be expressed as the ratio of two integers. In general, we use approximate decimal representation. But sometimes, errors are not allowed, and two integers must be used to represent a rational number.
At this point, we can establish a "rational number class", and 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 code



Question 6: Sorting of three parts

Topic description
There are many classic algorithms for general sorting, such as quick sort, Hill sort, etc.
However, in practical applications, there are often more or less special requirements. We don't need to apply those classic algorithms, we can build better solutions according to the actual situation.
For example, sort and sort the numbers in an integer array:
all negative numbers are on the left, positive numbers are on the right, and 0 is in the middle. Note that the characteristic of the problem is that order is not required in the negative and positive regions. You can use this feature to end the battle with one linear scan!!
The following program achieves 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 given array:
25,18,-2,0,16,-5,33,21,0,19,-16,25,-3,0
then sorted:
-3,-2,-16, -5,0,0,0,21,19,33,25,16,18,25
topic analysis
topic code



Question 7: Wrong bills

Topic description
A secret-related unit has issued some kind of bills, and they will all be recovered at the end of the year.
Each ticket has a unique ID number. The ID numbers for all notes throughout the year are consecutive, but the starting numbers of the IDs are randomly selected.
Due to the negligence of the staff, an error occurred when entering the ID number, resulting in a broken ID for one ID and a duplicate ID for another ID.
Your task is to programmatically find out the ID of the break number and the ID of the double number.
It is assumed that break numbers cannot occur at the largest and smallest numbers.
The program is required to first input an integer N (N<100) to represent the number of data lines that follow.
Then read in N lines of data.
The length of each line of data varies, and is a number of (not more than 100) positive integers (not more than 100,000) separated by spaces.
Each integer represents an ID number.

The program is required to output 1 line, containing two integers mn, separated by spaces.
Among them, m represents the break ID, n represents the repeat ID

Example:
User input:
2
5 6 8 11 9
10 12 9

Then the program output:
7 9

Another example:
User Enter:
6
164 178 108 109 180 155 141 159 104 182 171 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 151 143 175 120 161 134 162 190
149 138 142 146 1993 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

Then the program output:
105 120

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



Question 8: Lucky Numbers

Title description
The lucky number is named after the Polish mathematician Ulam. It is generated using a "sieve method" similar to generating prime numbers.
Start with 1 and write the natural numbers 1,2,3,4,5,6,…
1 is the first lucky number.
Let's start with the number 2. Delete all items whose sequence numbers are divisible by 2, and become:
1 _ 3 _ 5 _ 7 _ 9 ... Compress them and reorder them, as:
1 3 5 7 9 ... . At this time, 3 is the second lucky number, and then all the numbers in the serial number position that are 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 ones to be deleted should be 5, 11, 17, ...
At this time, 7 is the third lucky number, and then delete the position of the serial number that can be divisible by 7 ( 19,39,…)
the last remaining sequence is like:
1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75 , 79, …
This question requires:
Input two positive integers mn, separated by spaces (m < n < 1000*1000)
The program outputs the number of lucky numbers between m and n (excluding m and n).

Example:
User Input:
1 20
Program Output:
5

Example:
User Input:
30 69
Program Output:
8

Resource convention:
peak memory consumption (including virtual machine) < 64M
CPU consumption < 2000ms

topic analysis
topic code



Question 9: With Scores

Item description
100 can be expressed in the form of a fraction: 100 = 3 + 69258 / 714
can also be expressed as: 100 = 82 + 3546 / 197
Note features: In a fraction, the numbers 1 to 9 appear respectively and only once (excluding 0).
Like this with fractions, 100 has 11 representations.
Question requirements:
read a positive integer N (N<1000*1000) from the standard input, and the
program outputs the number with the numbers 1~9 without repetition and omission to form all the numbers with fractions.
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 Problem
analysis
problem code



Question 10: Number of consecutive intervals

Topic Description
Xiao Ming has been thinking about such a strange and interesting question these days:
How many consecutive intervals are there in a certain permutation of 1~N? The definition of the consecutive interval mentioned here is:
if all elements in the interval [L, R] (that is, the L-th to R-th elements of this arrangement) are sorted incrementally, a length of R-L+1 can be obtained. The "continuous" sequence is called the interval consecutive interval.
When N is small, Xiaoming can quickly calculate the answer, but when N becomes large, the problem is not so simple, and now Xiaoming needs your help.
Input format:
The first line is a positive integer N (1 <= N <= 50000), indicating the size 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 representing 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 is: [1,1], [1,2], [1,3], [1,4], [1,5], [2,2], [3,3], [4,4], [5,5]

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



Guess you like

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