2019 10th C/C++ 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 the real question analysis every day, so stay tuned

Lanqiao Cup Past Papers and Detailed Answers


Question 1: Team up (5 points)

Topic description
As a basketball team coach, you need to select one player
from position 1 to position 5 from the following list to form the team's starting lineup.
The scores of each player from position 1 to position 5 are shown in the table below. Would you please calculate the
maximum possible sum of the scores from the 1st to the 5th of the starting lineup ?
Insert picture description here
data

1 97 90 0 0 0
2 92 85 96 0 0
3 0 0 0 0 93
4 0 0 0 80 86
5 89 83 97 0 0
6 82 86 0 0 0
7 0 0 0 87 90
8 0 97 96 0 0
9 0 0 89 0 0
10 95 99 0 0 0
11 0 0 96 97 0
12 0 0 0 93 98
13 94 91 0 0 0
14 0 83 87 0 0
15 0 0 98 97 98
16 0 0 0 93 86
17 98 83 99 98 81
18 93 87 92 96 98
19 0 0 0 89 92
20 0 99 96 95 81

Question analysis
This question is directly hand-calculated, the question is selected, emmm.
Question code


Question answer

490

Question 2: Year character (5 points)

Title description
Xiao Ming uses the letter A to correspond to the number 1, B to 2, and so on, with Z to 26. For numbers above 27, Xiao Ming uses a string of two or more characters, for example, AA corresponds to 27, AB corresponds
to 28, AZ corresponds to 52, and LQ corresponds to 329.
What is the string corresponding to 2019? Problem
analysis
This problem is similar to a hexadecimal conversion, you can recall how to convert decimal to binary, and then think about converting decimal to 26, the formula is to divide p and take the remainder of the
problem code

#include<iostream>
#include<stack>
using namespace std;

int main()
{
    
    
	int n = 2019;
	stack<int> s;
	int temp;
	while(n)
	{
    
    
		temp = n % 26;
		s.push(temp);
		n/=26;
	}
	while(!s.empty())
	{
    
    
		char c =  s.top()+64;
		cout << c ;
		s.pop();
	}
	return 0;
} 

Question answer

BYQ

Question 3: Evaluation of a sequence of numbers (10 points)

Title description
Given a sequence of 1,1,1,3,5,9,17,..., starting from item 4, each item is the sum of the first three items. Find
the last 4 digits of item 20190324.
Problem analysis
Use an array to store the values ​​of three items, and add the numbers in turn by taking the remainder of 3. The last four digits should be kept, so you need to use 10000 to take the remainder after each calculation, otherwise the title code will overflow

#include<iostream>
using namespace std;

int main()
{
    
    
	int num[4] = {
    
    0,1,1,1};
	int index = 4;
	while(index<=20190324)
	{
    
    
		num[index%3] = num[1]+num[2]+num[3];
		num[index%3]%=10000;
		index++;
	}
	cout << num[index%3] <<endl;
	return 0;
} 

Question answer

4659

Fourth question: Decomposition of numbers (10 points)

Topic description
Decompose 2019 into the sum of three different positive integers, and require that each positive integer does not
contain the numbers 2 and 4. How many different decomposition methods are there?
Note that the order of exchanging 3 integers is considered the same method, for example, 1000+1001+18 and
1001+1000+18 are considered the same.
Question analysis
Violent cycle + digit judgment
question code

#include<iostream>

using namespace std;

//判断是否含有2 或 4 
bool check(int num)
{
    
    
	int temp = 0;
	while(num)
	{
    
    
		temp = num%10;
		if(temp==2||temp==4)
		{
    
    
			return false;
		} 
		num/=10;
	}
	return true;
}
int main()
{
    
    
	int ans = 0;
	for(int i = 1; i < 2019; i++)
	{
    
    
		if(check(i))
		//2019-i-j表示第三个数 j要比第三个数小 
		for(int j = i+1; j < 2019-i-j; j++)
		{
    
    
			if(check(j)&&check(2019-i-j))
			{
    
    
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
} 

Question answer

40785

Question 5: Labyrinth (15 points)

Title description The
following figure shows a plan view of a maze, where the obstacles marked 1 are obstacles, and
the places marked 0 are accessible.
010000
000100
001001
110000
The entrance of the maze is the upper left corner, and the exit is the lower right corner. In the maze, you can only walk from one position to
one of its four directions, up, down, left and right.
For the maze above, starting from the entrance, you can pass through the maze in the order of DRRURRDDDR, a
total of 10 steps. Among them, D, U, L, and R mean go down, up, left, and right respectively.
For the following more complicated maze (30 rows and 50 columns), please find a way to go through the maze,
which uses the least number of steps. Under the premise of the least number of steps , please find the one with the least lexicographical order as the answer.
Please note that D<L<R<U in lexicographic order. (If you copy the following text into a text file, be sure
the content will be copied to check whether there is consistent with the document in a file directory questions maze.txt,
the same content with the following text)
01010101001011001001010110010110100100001000101010
00001000100000101010010000100000001001100110100101
01111011010010001000001101001011100011000000010000
01000000001010100011010000101000001010101011001011
00011111000000101000010010100010100000101100000000
11001000110101000010101100011010011010101011110111
00011011010101001001001010000001000101001110000000
10100000101000100110101010111110011000010000111010
00111000001010100001100010000001000101001100001001
11000110100001110010001001010101010101010001101000
00010000100100000101001010101110100010101010000101
11100100101001001000010000010101010100100100010100
00000010000000101011001111010001100000101010100011
10101010011100001000011000010110011110110100001000
10101010100001101010100101000010100000111011101001
10000000101100010000101100101101001011100000000100
10101001000000010100100001000100000100011110101001
00101001010101101001010100011010101101110000110101
11001010000100001100000010100101000001000111000010
00001000110000110101101000000100101001001000011101
10100101000101000000001110110010110101101010100001
00101000010000110101010000100010001001000100010101
10100001000110010001000010101001010101011111010010
00000100101000000110010100101001000001000000000010
11010000001001110111001001000011101001011011101000
00000110100010001000100000001000011101000000110011
10101000101000100010001111100010101001010000001000
10000010100101001010110000000100101010001011101000
00111100001000010000000110111000000001000000001011
10000001100111010111010001000110111010101101111000
subject analysis
Topic code



Question 6: The sum of special numbers (15 points)

Title description
Xiao Ming is very interested in numbers containing 2, 0, 1, and 9 in the digits (excluding leading 0).
Such numbers from 1 to 40 include 1, 2, 9, 10 to 32, 39 and 40, total 28, their sum is 574.
Excuse me, what is the sum of all such numbers from 1 to n?
[Input format]
Input one line contains two integers n.
[Output format]
Output one line, including an integer, which represents the sum of the numbers that meet the conditions.
[Sample input]
40
[Sample output]
574
[Evaluation use case scale and conventions]
For 20% of evaluation use cases, 1 ≤ n ≤ 10.
For 50% of the evaluation use cases, 1 ≤ n ≤ 100.
For 80% of the evaluation use cases, 1 ≤ n ≤ 1000.
For all evaluation use cases, 1 ≤ n ≤ 10000.
[Output format]
Output an integer to represent the answer.
[Sample input]
7
1 6 5 4 3 2 1
Test question G: The weight of a complete binary tree 10
The 10th Blue Bridge Cup Software Provincial Contest C/C++ University Group B
[Sample Output]
2
[Evaluation use case scale and Convention]
For all evaluation use cases, 1 ≤ N ≤ 100000, −100000 ≤ A i ≤ 100000.
Topic analysis
Topic code



Question 7: The weight of a complete binary tree (20 points)

Description Title
given a complete binary tree comprising N nodes, each node of the tree has a weight in order from the
top to bottom, left to right, followed by A 1, A 2, ··· AN , As shown in the figure below:
Now Xiao Ming wants to add the weights of nodes with the same depth together. He wants to know which depth has the
largest sum of weights? If there are multiple depths with the same weight and the same maximum, please output the smallest depth.
Note: The depth of the root is 1.
[Input format] The
first line contains an integer N.
The second line contains N integers A 1, A 2, ··· AN.
[Output format]
Output an integer to represent the answer.
[Sample input]
7
1 6 5 4 3 2 1
Test question G: The weight of a complete binary tree 10
The 10th Blue Bridge Cup Software Provincial Competition C/C++ University Group B
[Sample Output]
2
[Evaluation use case scale and Convention]
For all evaluation use cases, 1 ≤ N ≤ 100000, −100000 ≤ A i ≤ 100000.
Topic analysis
topic codes



Question 8: Arithmetic sequence (20 points)

Title description The
math teacher gave Xiao Ming a question about the sum of arithmetic series. But the careless Xiao Ming forgot
part of the sequence, only N integers.
Now given these N integers, Xiao Ming wants to know how many
items are the shortest arithmetic sequence containing these N integers ?
[Input format]
The first line of input contains an integer N.
The second line contains N integers A 1, A 2, ···, AN. (Note that A 1 ∼ AN are not necessarily
given in the order in the arithmetic sequence)
[Output format]
Output an integer to represent the answer.
[Sample input]
5
2 6 4 10 20
[Sample output]
10
[Sample description]
The shortest arithmetic sequence including 2, 6, 4, 10, 20 is 2, 4, 6, 8, 10, 12 , 14, 16,
18 , 20.

[Evaluation use case scale and agreement]
For all evaluation use cases, 2 ≤ N ≤ 100000, 0 ≤ A i ≤ 10 9.
Topic analysis
topic codes



Question 9: Suffix expression (25 points)

Title description
Given N plus signs, M minus signs, and N + M + 1 integers A 1, A 2 ,..., A N+M+1, Xiao
Ming wants to know where all the N plus signs are , M minus signs and N + M +1 integers
, which is the largest result of the legal postfix expression?
Please output this maximum result.
For example, if 1 2 3 +-is used, the result of the postfix expression "2 3 + 1 -" is 4, which is the largest.
[Input format] The
first line contains two integers N and M.
The second line contains N + M + 1 integers A 1, A 2 ,..., A N+M+1.
[Output format]
Output an integer, representing the answer.
[Sample input]
1 1
1 2 3
[Sample output]
4
[Evaluation use case scale and conventions]
For all evaluation use cases, 0 ≤ N, M ≤ 100000, −10 9 ≤ A i ≤ 10 9.
Topic analysis
topic codes



Question 10: Psionic Transmission (25 points)

Title description
[title background]
In the game "StarCraft II", the high-level templar is an important AOE unit of the Protoss,
playing an important role in the middle and late stages of the game. Its skill "Psionic Storm" can consume a lot of Psionic energy
causes devastating damage to enemy forces in an area. Often used to fight against human biochemical forces and Zerg
Hydralisk and other low-health units.
[Problem description]
You control n high-ranking templars, which are labeled 1,2,...,n for convenience. Every high-level templar
needs a certain amount of psionic energy to fight, and each person has a psionic value ai, which indicates how much psionic energy he has (ai
non-negative means that this high-level templar is more than in the best state If ai points psionic power, if ai is negative, it means that this
high-level templar still needs −ai points psionic power to reach the best combat state). Now the system gives
your high-level templar an ability to transfer psionic energy, and each time you can choose an i ∈ [2,n − 1], if
ai ≥ 0, then the high-level templar on both sides, that is i − 1, i + 1 These two high-level templars will
each draw ai points of psionic power from the high-level templar
of i ; if ai <0, the high-level templars on both sides will be i −1,i+1 These two high-level templars will give the high-level templar i -ai points of psionic power. In
terms of formalization, it is ai−1 + = ai, a i+1 + = ai, ai − = 2a i.
Psionic energy is a very efficient combat tool. It is also very dangerous and unstable. It is
not good for a high-level templar to have too much or too little psionic power. The instability of a group of high-level templars is defined as
max n
i=1 |ai |, please pass the psionic operation unlimited times to
minimize the instability of the group of high-level templars you control .
[Input format]
This question contains multiple sets of questions. The first line of input contains a positive integer T to indicate the number of query groups.
Then enter each set of queries in turn.
The first line of each group of queries contains a positive integer n, which represents the number of high-level templars.
The next line contains n numbers a 1, a 2 ,...,an.
Test Question J: Psionic Transmission 15
The 10th Blue Bridge Cup Software Provincial Competition C/C++ University Group B
[Output Format]
Output T lines. An integer in each line indicates the answer to each group of queries in turn.
[Sample input]
3
3
5 -2 3
4
0 0 0 0
3
1 2 3
[Sample output]
3
0
3
[Sample description]
For the first group of queries:
transfer operation to the high-level templar No. 2 After that, a 1 = 3, a 2 = 2, and a 3 = 1. The answer is 3.
For the second group of questions:
this group of high-ranking templars possesses the psionic power that can make them reach the best combat state.
[Sample input]
3
4
-1 -2 -3 7
4
2 3 4 -8
5
-1 -1 6 -1 -1
[Sample output]
5
7
4
[Sample input]
See file trans3.in.
[Sample output]
See file trans3.ans.
[Data scale and convention]
For all evaluation use cases, T ≤ 3, 3 ≤ n ≤ 300000, |ai | ≤ 10 9.
During the evaluation, you will use 25 evaluation cases to test your program. The restrictions of each evaluation case are as follows:
Evaluation case number n |ai | Special properties
1 = 3 ≤ 1000 No
2, 3 ≤ 5 ≤ 1000 No
4,5,6, 7 ≤ 10 ≤ 1000 None
8, 9, 10 ≤ 20 ≤ 1000 None
11 ≤ 100 ≤ 10 9 All ai non-negative
12, 13, 14 ≤ 100 ≤ 10 9 None
15, 16 ≤ 500 ≤ 10 9 None
17, 18, 19 ≤ 5000 ≤ 10 9 None
20 ≤ 5000 ≤ 10 9 All ai are non-negative
21 ≤ 100000 ≤ 10 9 All ai are non-negative
22,23 ≤ 100000 ≤ 10 9 None
24,25 ≤ 300000 ≤ 10 9 Untitled
analysis
question code



Guess you like

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