The real questions of the 5th Java Group A Blue Bridge Cup Provincial Competition in 2014

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: Guess the age

Title description
Xiao Ming took two younger sisters to participate in the Lantern Festival. When someone asked them how old they were, they said mischievously: "The product of our age is 6 times the sum of our ages." Xiao Ming added: "They are not twins, and the age difference must be no more than 8 years old."
Please write down: the age of Xiao Ming's younger sister.
Topic analysis
topic codes



The second question: Li Bai hits wine

Title description
Li Bai, a great poet, has a good drink all his life. Fortunately, he never drives.
One day, he came out of the house carrying a hip flask with two buckets of wine in it. He sang as he
walked : Walk on the street without incident, carry a pot to drink.
Double at every store, drink a bucket when you meet flowers.
Along the way, he encountered the store 5 times and spent 10 times. Knowing that the last time he met was the flower, he just drank the wine.
Please calculate the sequence of Li Bai’s encounters with shops and flowers. You can record encounters with shops as a and encounters with flowers as b. Then: babaabbabbabbbb is a reasonable order. How many answers are there like this? Please calculate the number of all possible solutions (including those given by the title).
Note: Submit the answer via the browser. The answer is an integer. Don't write any extra content.
Topic analysis
topic codes



Question 3: Magical formula

Title description
A multiplication formula consisting of 4 different numbers, their product is still composed of these 4 numbers.
For example:
210 x 6 = 1260
8 x 473 = 3784
27 x 81 = 2187
all meet the requirements.
If the formulas satisfying the commutative law of multiplication are counted as the same case, then, including the three cases listed above, how many formulas are there to satisfy the requirements?
Please fill in the number, submit the answer through the browser, and do not fill in extra content (for example: list all calculations).
Topic analysis
topic codes



Fourth question: write a log

Title description
Writing a log is a common task of the program. Now it is required to write logs alternately among the three files t1.log, t2.log, and t3.log. In other words, t1.log is written for the first time, t2.log is written for the second time, ... t1.log is still written for the fourth time, and so on.
The following code simulates this logic of writing to different log files in turn.
Please fill in the missing code in the underlined part. Submit the answer via the browser.
Note: Do not fill in the existing content of the title, and do not fill in any description or explanation text.

public class A
{
    
    
	private static int n = 1;
	
	public static void write(String msg)
	{
    
    
		String filename = "t" + n + ".log";
		n = ____________;
		System.out.println("write to file: " + filename + " " + msg);
	}
}

Topic analysis
topic codes



Question 5: Championship

Title description
If you want to select the first and second largest data from n data (requires the location and value of the output data), what method is used to compare the least number of times? We can be inspired by sports championships. As shown in the figure [1.png], in a tournament of 8 players, first catch and compare each other and eliminate half of them. The winners competed in pairs...until the first place was decided. After the first place is output, just re-match the position marked in yellow. The following code implements this algorithm (assuming that there are no identical values ​​in the data). The code needs to use an array to represent the tree in the figure (note that this is a full binary tree, and the shortcomings need to be filled). It does not store the data itself, but stores the subscript of the data. After the first data is output, its location is marked as -1

class A{
    
    
   	//a 表示待处理的数据,长度如果不是2的次幂,则不足位置补为-1
	static void pick(int[] a)
	{
    
    
		int n = 1;
		while(n<a.length) n *= 2;
		
		
		int[] b = new int[2*n-1];
		for(int i=0; i<n; i++){
    
     
			if(i<a.length) 
				b[n-1+i] = i;
			else
				b[n-1+i] = -1;
		}
		
		//从最后一个向前处理
		for(int i=b.length-1; i>0; i-=2){
    
    
			if(b[i]<0){
    
    
				if(b[i-1]>=0)
					b[(i-1)/2] = b[i-1]; 
				else
					b[(i-1)/2] = -1;
			}
			else{
    
    
				if(a[b[i]]>a[b[i-1]])
					b[(i-1)/2] = b[i];
				else
					b[(i-1)/2] = b[i-1];
			}
		}
		
		//输出树根
		System.out.println(b[0] + ": " + a[b[0]]);
		
		//值等于根元素的位置需要重新pk
		pk(a,b,0,b[0]);
		
		//再次输出树根
		System.out.println(b[0] + ": " + a[b[0]]);
	}
 
	// a 表示待处理数据,b 二叉树,k 当前要重新比拼的位置,v 已经决胜出的值	
   	static void pk(int[] a, int[] b, int k, int v)
	{
    
    
		
		int k1 = k*2+1;
		int k2 = k1 + 1;
		
		if(k1>=b.length || k2>=b.length){
    
    
			b[k] = -1;
			return;
		}
		
		if(b[k1]==v) 
			pk(a,b,k1,v);
		else
			pk(a,b,k2,v);
		
		
		//重新比较
		if(b[k1]<0){
    
    
			if(b[k2]>=0)
				b[k] = b[k2]; 
			else
				b[k] = -1;
			return;
		}
		
		if(b[k2]<0){
    
    
			if(b[k1]>=0)
				b[k] = b[k1]; 
			else
				b[k] = -1;
			return;
		}
		
		if(__________________________)  //填空
			b[k] = b[k1];
		else
			b[k] = b[k2];
	}
}

Please carefully analyze the process and fill in the missing codes.
Submit the answer through the browser, only fill in the missing code, do not fill in the existing code or other explanation sentences, etc.
Insert picture description here

Topic analysis
topic codes



Sixth question: Hexagon filling

Title description In the
hexagon as shown in the picture [1.png], fill in the numbers from 1 to 12.
Make the sum of the numbers on each straight line the same.
In the picture, 3 numbers have been filled in for you. Could you please calculate the number represented by the asterisk?
Please submit the answer through the browser, do not fill in the extra content.
Insert picture description here

Topic analysis
topic codes



Question 7: Rope loop

Title description
There are 100 ropes today, of course there will be 200 rope ends.
If any rope ends are paired in pairs, tie all the rope ends together. In the end, several rope loops will be formed (regardless of whether they are put together).
Our question is: Please calculate how many loops will be formed with the greatest probability?
Note: The result is an integer, please submit the number through your browser. Don’t fill in extra content.
Topic analysis
topic codes



Question 8: Langton Ant

Title description
Langton ant, proposed by Chris Langton in 1986, is a type of cellular automata.
The square grids on the plane are filled with black or white. There is an "ant" in one of the squares. The head orientation of the ant is: up, down, left, and right.
The rules of ant movement are very simple: if the ant is in a black grid, turn right 90 degrees, change the grid to a white grid, and move forward one square; if the ant is in a white grid, turn left 90 degrees, change the grid to black Grid and move forward one grid.
Although the rules are simple, the behavior of ants is very complicated. The route left at the beginning will be nearly symmetrical, as if it will be repeated, but no matter what the initial state, the ants will open up a regular "highway" after a long chaotic activity.
The route of the ant is difficult to predict in advance.
Your task is to simulate the position of the Langton ant after the nth walk based on the initial state.
【Data Format】

The first line of the input data is two integers of mn (3 <m, n <100), indicating the number of rows and columns of the square grid.
Next is m rows of data.
Each line of data is n numbers separated by spaces. 0 means white grid, 1 means black grid.

Next is a row of data: xysk, where xy is an integer, indicating the row number and column number where the ant is located (the row number increases from top to bottom, and the column number increases from left to right, all numbers start from 0). s is a capital letter, which indicates the direction of the ant's head. We agree to use: UDLR for up, down, left, and right. k represents the number of steps the ant takes.

The output data is two integers pq separated by spaces, which respectively represent the row number and column number of the grid where the ant is after k steps.

For example, input:
5 6
0 0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
2 3 L 5 The
program should output:
1 3

For another example, input:
3 3
0 0 0
1 1 1
1 1 1
1 1 U 6 The
program should output:
0 0

Resource agreement:
peak memory consumption (including virtual machines) <256M
CPU consumption <1000ms

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.7 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 9: Fibonacci

Title Description The
Fibonacci sequence is very familiar to everyone. Its definition is:
f(x) = 1… (x=1,2)
f(x) = f(x-1) + f(x-2)… (x>2)
For a given integer n and m, we want to find:
f(1) + f(2) +… + the value of f(n). But this value may be very large, so we take it modulo f(m).
See [Figure 1.png] for the formula,
but this number is still very large, so we need to modulo p again.
[Data format]
Input as a line of integers separated by spaces nmp (0 <n, m, p <10^18),
output as 1 integer

For example, if you enter:
2 3 5, the
program should output:
0

For another example, input:
15 11 29 The
program should output:
25

Resource agreement:
Peak memory consumption (including virtual machines) <256M
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.7 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: Fluctuation series

Title description
Observe this sequence:
1 3 0 2 -1 1 -2 …
The latter item in this sequence always increases by 2 or decreases by 3 compared to the previous item.
Dongdong is very curious about this kind of sequence. He wants to know how many integer sequences are possible with length n and s and the latter term always increases a or decreases b than the previous term?
[Data format]
The first line of input contains four integers nsab, the meaning is as mentioned above.
Output a line, containing an integer, indicating the number of solutions that meet the conditions. Since this number is very large, please output the remainder of the number of plans divided by 100000007.

For example, input:
4 10 2 3 The
program should output:
2

[Sample description]
These two numbers are 2 4 1 3 and 7 4 1 -2 respectively.

[Data scale and convention]
For 10% of data, 1<=n<=5, 0<=s<=5, 1<=a,b<=5;
for 30% of data, 1<=n<= 30, 0<=s<=30
, 1 <=a,b<=30; for 50% of the data, 1<=n<=50, 0<=s<=50, 1<=a,b<= 50;
For 70% of data, 1<=n<=100, 0<=s<=500
, 1<= a, b<=50; For 100% of data, 1<=n<=1000, -1,000,000,000 <=s<=1,000,000,000, 1<=a, b<=1,000,000.

Resource agreement:
Peak memory consumption (including virtual machines) <256M
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.7 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/111832259