2013 4th Java Group A Blue Bridge Cup Provincial Competition Zhenti

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: 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) Start
from me, start from me
, start
from
me
In the grid with the word "from" written on it, you can jump to the adjacent grid horizontally or vertically, but you cannot jump to the diagonal grid or other positions. 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?
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 3: Mersenne Primes

Problem Description
A number is called a "perfect number" or "perfect number" if the sum of all its true factors equals itself. For example:
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
early in 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. where ^ represents the "power" operation, and power has a higher priority than the four arithmetic operations, for example: 2^3 = 8, 2 * 2^3 = 16, 2^3-1 = 7 but people quickly found that when n When it is very large, it is still a difficult problem to determine whether a large number is prime or not. Because of the conjecture of the French mathematician Mersen, we are used to call the prime numbers in the form: 2^n - 1: Mersenne primes. As of February 2013, only 48 Mersenne primes have been found. The newly found Mersenne prime is too large to see the whole picture with general programming ideas, so we reduce the difficulty of the task a little: In 1963, the University of Illinois in the United States commemorated the 23rd Mersenne prime they found n=11213, in "2^11213-1 is a prime number" was printed on every envelope that was sent. 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 code



Question 4: Upside-down price tags

Topic description
Xiao Li's store specializes in sample TV sets that have been removed from other stores, so it can be called a sample TV store. The price tag is 4 digits (that is, ranging from thousands of dollars). In order to make the price clear and convenient, Xiao Li used a prefabricated price tag similar to a digital tube, and just painted the numbers with a color pen (see p1.jpg). This kind of price tag has a characteristic. For some numbers, it is also a reasonable number in reverse. Such as: 1 2 5 6 8 9 0 can be. In this way, if the brand is hung upside down, it may be completely changed to another price, for example: 1958 hanging upside down is: 8561, which is a few thousand yuan difference!! Of course, in most cases, it cannot be read backwards, for example, 1110 is It cannot be reversed because 0 cannot be used as a starting number. One day, tragedy finally happened. A clerk accidentally hung up two of the price tags in the store. And the TVs of these two price tags have been sold! Fortunately, the price difference is not large. One of the price tags lost more than 200, and the other price tag made more than 800. Combined, they made more money. 558 yuan.
Calculate based on this information: What should be the correct price for the losing price tag?
The answer is a 4-digit integer, please submit the number directly through your browser.
Note: Do not submit a solution process, or other explanatory content.
insert image description here

topic analysis
topic code



Question 5: Sorting of the 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

Please analyze the code logic, speculate the code at the underline, and submit it through the web page
Note: Only take the missing code as the answer, and never fill in redundant codes, symbols or explanatory text! !
topic analysis
topic code



Question 6: Reverse Polish Expressions

Topic description
Normal expressions are called infix expressions. The operator is in the middle, which is mainly for human reading, and it is not convenient for machines to solve. For example: 3 + 5 * (2 + 6) - 1 Also, parentheses are often required to change the order of operations. On the contrary, if the reverse Polish expression (prefix expression) is used, the above expression is expressed as: - + 3 * 5 + 2 6 1
No need for parentheses, and the machine can easily solve it recursively.
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 a reverse Polish representation string.
Its return value is an array: the first element is the result of the evaluation, and the second is 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, speculate the code at the line, and submit it through the web page.
Note: Use only missing codes as answers, never fill in extra codes, symbols or explanatory text! !
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.
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
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 153 193 144 166 171 194 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 resource agreed
: peak Memory consumption (including virtual machine) < 64M CPU consumption < 2000ms



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.
Note: Do not use the package statement. Do not use 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 code



Question 8: 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
Please output strictly according to the requirements, do not add superfluous prints like: "Please enter..." redundant.
All code is placed in the same source file, after debugging, copy and submit the source code.
Note: Do not use the package statement. Do not use 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 code



Question 9: Cut the lattice

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 figure to get two parts, each of which sums to 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, output the minimum number of cells contained in the area containing the upper left cell. If it cannot be divided, output 0.
Program input and output format requirements:
the program first reads two integers mn, and divides them with spaces (m, n<10)
to indicate the width and height of the table,
followed by n lines, each line contains m positive integers, Separate with spaces. Each integer is not greater than 10000
Program output: In all solutions, the minimum number of cells that the partition containing the upper left corner may contain.
For example:
user input:
3 3
10 1 52
20 30 1
1 2 3
then program output:
3
Another example:
user input:
4 3
1 1 1 1
1 30 80 2
1 1 1 100
then program output:
10
(see p2. jpg)
Resource convention:
Peak memory consumption (including virtual machine) < 64M
CPU consumption < 5000ms
Please output strictly according to the requirements, and do not superfluously print redundant content like: "Please enter...".
All code is placed in the same source file, after debugging, copy and submit the source code.
Note: Do not use the package statement. Do not use 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 image description here

topic analysis
topic code



Question 10: Minister's Travel Expenses

Title Description
A long time ago, the T Kingdom prospered unprecedentedly. 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 developed a set of excellent construction plans after thinking, so that any big city can be reached directly from the capital or indirectly through other big cities. At the same time, the plan to reach each big city from the capital is unique if it does not pass through the big cities repeatedly. J is an important minister of country T. He patrols the major cities and observes the public sentiment. So, going from one city to another without stopping has become J's most common thing to do. He has a purse to store travel expenses between cities. Smart J found that if he did not stop for repairs in a certain city, in the process of continuous travel, the toll he spent was related to the distance he had traveled. In (x is an integer), he spends as much as x+10. That is to say, it costs 11 to walk 1 km, and 23 to walk 2 km. Minister J would like to know: What is the maximum travel expenses he may spend from a certain city to another city without rest in between?
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 from 1, and city No. 1 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 at most.
Sample input:
5
1 2 2
1 3 1
2 4 5
2 5 4

Sample output:
135

Example description:
Minister J costs 135 to travel from city 4 to city 5.

Consider supporting larger data sizes whenever possible based on resource constraints.

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

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.
Note: Do not use the package statement. Do not use 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 code



Guess you like

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