The 10th C/C++ Group B Blue Bridge Cup Provincial Competition in 2019

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 question analysis is updated every day, so stay tuned

Blue Bridge Cup real questions and detailed answers over the years


Question 1: Team up (5 points)

Topic Description
As a basketball coach, you need to select one player from the following list from positions 1 to 5 to
form the team's starting lineup.
The ratings for each player from 1 to 5 are shown in the table below. Can you calculate
the maximum possible sum of the ratings of the starting lineup's 1st to 5th positions?
insert image 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
_


question answer

490

Question 2: Year characters (5 points)

Topic description
Xiao Ming uses the letter A to correspond to the number 1, B to 2, and so on, Z corresponds to 26. For numbers above 27, Xiaoming uses a string of two or more digits to correspond, for example, AA corresponds to 27, AB corresponds
to 28, AZ corresponds to 52, and LQ corresponds to 329.
What is the corresponding string for 2019?
Question Analysis This question
is similar to a base conversion. You can recall how to convert decimal to binary, and then think about converting decimal to 26 base. The formula is to divide p and take the remainder.

#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: Sequence Evaluation (10 points)

Problem Description
Given a sequence of 1, 1, 1, 3, 5, 9, 17, ..., starting from the 4th item, each item is the sum of the previous 3 items. Find
the last 4 digits of item 20190324.
Problem analysis
Use an array to store three values, and add the numbers in turn by taking the remainder of 3. The last four digits should be reserved, so after each calculation, you need to take the remainder of 10000, otherwise the
question 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

Question 4: Decomposition of Numbers (10 points)

Topic description
Decompose 2019 into the sum of 3 different positive integers, and require that each positive integer does not
contain the numbers 2 and 4, how many different decomposition methods are there in total?
Note that swapping the order of 3 integers is considered the same method, for example 1000+1001+18 and
1001+1000+18 are considered the same.
Topic analysis
Violent cycle + number of digits to judge the
topic 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: Maze (15 points)

Problem Description
The following figure shows a plan view of a maze, in which the obstacles marked with 1 are obstacles and
the places marked with 0 can be passed.
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 above maze, 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 represent going down, up, left, and right, respectively.
For the more complicated maze below (30 rows and 50 columns), find a way to go through the maze that
uses the least number of steps, and with the fewest steps, find the answer with the smallest lexicographical order.
Note that D<L<R<U in the lexicographical 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: Sum of Special Numbers (15 points)

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



Question 7: Weights of Complete Binary Trees (20 points)

Topic description
Given a complete binary tree with N nodes, each node in the tree has a weight, which are A 1 , A 2 , . . . AN in order
from top to bottom and left to right. As shown in the figure below:
Now Xiaoming wants to add the weights of nodes of the same depth together. He wants to know which depth node
has the largest sum of weights? If there are multiple depths with the same maximum weight, please output the smallest depth.
Note: The depth of the root is 1.
【Input format】
The first line contains an integer N.
The second row 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: Weight of complete binary tree 10
The 10th Blue Bridge Cup Software Provincial Competition C/C++ University Group B
[Sample Output]
2
[The scale of the evaluation use case and Convention]
For all evaluation cases, 1 ≤ N ≤ 100000, −100000 ≤ A i ≤ 100000.
topic analysis
topic code



Question 8: Arithmetic Sequence (20 points)

Problem description
The math teacher gave Xiao Ming a problem of summing arithmetic sequences. But the careless Xiao Ming forgot
part of the sequence, and only remembered the N integers.
Now given these N integers, Xiaoming wants to know how many terms are there in the shortest arithmetic sequence containing these N integers
?
【Input format】
The first line of input contains an integer N.
The second row contains N integers A 1 , A 2 , . . . , AN . (Note that A 1 ∼ AN is not necessarily given in the order of arithmetic
progression)
[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.

[Scale and conventions of evaluation cases]
For all evaluation cases, 2 ≤ N ≤ 100000, 0 ≤ A i ≤ 10 9 .
topic analysis
topic code



Question 9: Postfix Expressions (25 points)

Problem Description
Given N plus signs, M minus signs, and N + M + 1 integers A 1 , A 2 ,
. , M minus signs, and N + M + 1 integers
, which one has the largest result?
Please output this maximum result.
For example, using 1 2 3 + -, the result of the suffix 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 case scale and convention]
For all evaluation cases, 0 ≤ N, M ≤ 100000, −10 9 ≤ A i ≤ 10 9 .
topic analysis
topic code



Question 10: Psionic Transmission (25 points)

Title Description
[Title Background]
In the game "StarCraft II", the high-level Templar, as an important AOE unit of the Protoss,
plays an important role in the middle and late stages of the game, and its skill "Psionic Storm" can consume a lot of Psionics
inflicts devastating damage to enemies in an area. Often used against low-health units such as the human biochemical troops and the Zerg's
Hydralisks.
[Problem Description]
You control n High Templars, labeled 1,2,... ,n for convenience. Each high-level templar
needs a certain amount of psionic power to fight, and each person has a psionic value ai that indicates how much psionic power he has (a
non-negative ai means that this high-level templar is more redundant than in the best state Ai points of psionic power, negative ai means that the
high templar still needs −ai points of psionic power to reach the best combat state). Now the system has given
your high-level templar an ability to transmit psionic energy, each time you can choose a i ∈ [2,n − 1], if
ai ≥ 0, then the high-level templars on both sides of it, that is, i − 1, i + 1 These two high-ranking templars will
draw ai points from each high-ranking templar i; if ai < 0, then the high-ranking templars on both sides,
i.e. −1,i+1 These two high templars will give i the high templar −ai points of psionic power. Formally
speaking, it is ai−1 + = ai , a i+1 + = ai , ai − = 2a i .
Psionic power is a very efficient combat tool, but 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 use an unlimited number of teleportation psionic manipulations
to minimize the instability of the group of High Templars you control.
【Input format】
This question contains multiple groups of questions. The first line of input contains a positive integer T representing the number of query groups.
Then enter each set of queries in turn.
The first line of each set of queries contains a positive integer n representing the number of High Templars.
The next line contains n numbers a 1 ,a 2 ,... ,an .
Question J: Psionic Transmission 15
The 10th Blue Bridge Cup Competition Software Provincial Competition C/C++ University Group B
[Output Format]
Output T lines. One integer per line represents the answer to each set 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:
transmit the No. 2 high-level Templar After a 1 = 3, a 2 = 2, a 3 = 1. The answer is 3.
For the second set of inquiries:
This group of high-ranking templars possessed the psionic powers that would allow them to be at their best in combat.
【Sample input】
3
4
-1 -2 -3 7
4
2 3 4 -8
5
-1 -1 6 -1 -1
【Example output】
5
7
4
【Example input】
See file trans3.in.
[Sample output]
See the file trans3.ans.
[Data scale and conventions]
For all evaluation cases, T ≤ 3, 3 ≤ n ≤ 300000, |ai | ≤ 10 9 .
25 evaluation cases will be used to test your program during evaluation, each evaluation case is limited as follows:
evaluation case number n | ai | special properties
1 = 3 ≤ 1000 none
2,3 ≤ 5 ≤ 1000 none
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 non-negative
21 ≤ 100000 ≤ 10 9 all ai non-negative
22,23 ≤ 100000 ≤ 10 9 none
24,25 ≤ 300000 ≤ 10 9 no
topic analysis
topic code



Guess you like

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