2013 4th 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: 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: Revitalizing China

Topic description
Xiao Ming participated in the school's fun sports meet, one of which is: jumping grid. Draw some grids on the ground, and write a word 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 In the grid where the word "from" is written, you can jump to the adjacent grid horizontally or vertically, but not to the diagonal grid or other positions. 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?
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



Question 3: Mersenne prime numbers

Title description
If the sum of all true factors of a number is equal to itself, it is called a "perfect number" or "perfect number". For example:
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
as early as AD More than 300 years ago, Euclid gave the theorem for determining perfect numbers:
if 2^n-1 is a prime number, then 2^(n-1) * (2^n-1) is a perfect number. Among them, ^ means "power" operation, the priority of power is higher than the four arithmetic operations, for example: 2^3 = 8, 2 * 2^3 = 16, 2^3-1 = 7, but people quickly discovered that when n When it is very large, it is still difficult to determine whether a large number is prime or not. Because of the conjecture of the French mathematician Mason, we are accustomed to call the prime numbers of the form: 2^n-1: Mersenne prime numbers. As of February 2013, only 48 Mersenne prime numbers have been found. The newly found Mersenne prime number is too large to get a complete picture of it with general programming ideas, so we reduce the difficulty of the task a bit: In 1963, the University of Illinois, USA, to commemorate the 23rd Mersenne prime number n=11213 they found, The words "2^11213-1 is a prime number" are printed on every envelope sent out. 2^11213-1 This number is already very large (more than 3000 digits), please program to find the last 100 digits of the decimal representation of this prime number.
Topic analysis
topic codes



Fourth question: Inverted price tag

Title description
Xiao Li’s store specializes in sample TVs that are off the shelves in other stores. It can be called a sample TV store. The price is 4 digits (that is, thousands of yuan). In order to make the price clear and convenient, Xiao Li used a pre-made price tag similar to a digital tube, as long as he painted the numbers with a colored pen (see p1.jpg). This kind of price tag has a characteristic, for some figures, it is reasonable to look at it backwards. For example: 1 2 5 6 8 9 0 is all right. In this way, if the brand hangs upside down, it may completely change to another price, for example: 1958 upside down is: 8561, which is a few thousand yuan off!! Of course, in most cases, you can’t read it backwards, for example, 1110 It cannot be reversed, because 0 cannot be used as the starting number. One day, the tragedy finally happened. A clerk accidentally hung up two price tags in the store. And the TV sets of these two price brands have been sold! Fortunately, the price difference is not big. One of the price tags lost more than 200, while the other price tag earned more than 800. All together, it made more. 558 yuan.
Please calculate based on this information: What is the correct price of the price tag that lost money?
The answer is a 4-digit integer, please submit the number directly through the browser.
Note: Do not submit the answering process or other supporting explanation content.
Insert picture description here

Topic analysis
topic codes



Fifth question: Three parts sort

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

Please analyze the code logic, and guess the code at the underline, and submit it through the webpage.
Note: Only use the missing code as the answer, and do not fill in the extra code, symbols or explanatory text! !
Topic analysis
topic codes



Question 6: Inverse Polish expression

Title description
Normal expressions are called infix expressions. The operator is in the middle, which is mainly for human reading, and it is not convenient to solve by machine. For example: 3 + 5 * (2 + 6)-1 Moreover, it is often necessary to use parentheses to change the order of operations. On the contrary, if it is expressed in reverse Polish expression (prefix expression), the above formula is expressed as:-+ 3 * 5 + 2 6 1
No parentheses are needed, and the machine can solve it easily by recursive method.
For simplicity, we assume:
1. There are only three operators +-*
2. Each operand is a non-negative integer less than 10 The
following program evaluates an inverse Polish representation string.
The return value is an array: the first element represents the evaluation result, and the second element represents the number of characters it has parsed.

	static int[] evaluate(String x)
	{
    
    
		if(x.length()==0) return new int[] {
    
    0,0};
		
		char c = x.charAt(0);
		if(c>='0' && c<='9') return new int[] {
    
    c-'0',1};
		
		int[] v1 = evaluate(x.substring(1));
		int[] v2 = __________________________________________;  //填空位置
		
		int v = Integer.MAX_VALUE;
		if(c=='+') v = v1[0] + v2[0];
		if(c=='*') v = v1[0] * v2[0];
		if(c=='-') v = v1[0] - v2[0];
		
		return new int[] {
    
    v,1+v1[1]+v2[1]};
	}

Please analyze the code logic and guess the code at the underline, and submit it through the web.
Note: Only use the missing code as the answer, and do not fill in extra codes, symbols or explanatory text! !
Topic analysis
topic codes



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 stands for broken ID, n stands for repeated ID.
For example:
user input:
2
5 6 8 11 9
10 12 9
then 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

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.
Note: Do not use the package statement. Do not use the features of jdk1.6 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.
Topic analysis
topic codes



Question 8: 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
Please output strictly as required, and do not superfluously print something like: "Please enter..."
All the codes are placed in the same source file. After the debugging is passed, copy and submit the source code.
Note: Do not use the package statement. Do not use the features of jdk1.6 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.
Topic analysis
topic codes



Question 9: Cut the grid

Title description
As shown in Figure p1.jpg, some integers are filled in the 3 x 3 grid.
We cut along the red line in the picture, and got two parts, the sum of each part is 60. The requirement of this question is to ask you to program to determine whether the integer in the given mxn grid can be divided into two parts so that the sum of the numbers in these two areas is equal. If there are multiple solutions, please output the minimum number of grids contained in the area containing the top left grid. If it cannot be divided, then output 0.
Program input and output format requirements: the
program first reads in two integers mn divided by spaces (m, n<10) to
indicate the width and height of the table.
Next are n rows, each with m positive integers. Separate with spaces. Each integer is not greater than 10000. The
output of the program: In all the solutions, the smallest number of grids that may be contained in the partition in the upper left corner is included.
For example:
user input:
3 3
10 1 52
20 30 1
1 2 3
program output:
3
another example:
user input:
4 3
1 1 1 1
1 30 80 2
1 1 1 100
program output:
10
(see p2. jpg)
Resource agreement:
Peak memory consumption (including virtual machine) <64M
CPU consumption <5000ms
Please output strictly according to the requirements, do not 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.
Note: Do not use the package statement. Do not use the features of jdk1.6 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.
Insert picture description here

Topic analysis
topic codes



Question 10: Minister’s travel expenses

Title Description
Long ago, Kingdom T was prosperous. In order to better manage the country, the kingdom has built a large number of expressways to connect the capital and major cities in the kingdom. In order to save money, the ministers of Country T have formulated an excellent construction plan after thinking, so that any big city can be reached directly from the capital or indirectly through other big cities. At the same time, if you don't repeatedly pass through big cities, the plan from the capital to each big city is unique. J is an important minister of country T. He patrols between major cities to understand the people's sentiments. Therefore, non-stop from one city to another has become the most common thing J does. He has a purse to store travel expenses between cities. The clever J found that if he does not stop to repair in a certain city, the travel expenses he spends during the continuous journey are related to the distance he has traveled, and he is walking the kilometer from the xth kilometer to the x+1th kilometer. Medium (x is an integer), his travel expenses are x+10 so much. In other words, it costs 11 to walk 1 kilometer and 23 to walk 2 kilometers. Minister J wanted to know: What is the maximum amount of travel expenses that he might spend when starting from a certain city without taking a break and arriving in another city?
Input format:
The first line of input contains an integer n, which represents the number of
cities in Kingdom T including the capital. The cities are numbered sequentially starting from 1, and the first city is the capital.
The next n-1 lines describe the highways in country T (the highways in country T must be n-1).
Each line has three integers Pi, Qi, Di, indicating that there is a highway between city Pi and city Qi. The length is Di kilometers.
Output format:
output an integer, indicating how much the minister J spends the most on the road.
Sample input:
5
1 2 2
1 3 1
2 4 5
2 5 4

Sample output:
135

Example explanation:
Minister J will spend 135 toll to travel from city 4 to city 5.

Consider supporting larger data scales as much as possible based on resource constraints.

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

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.
Note: Do not use the package statement. Do not use the features of jdk1.6 and above.
Note: The name of the main class must be: Main, otherwise it will be processed as invalid code.
Topic analysis
topic codes



Guess you like

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