2020 11th C/C++ Group A 2nd Blue Bridge Cup Provincial Match 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: Making House Numbers

Title description
Xiaolan wants to make house numbers for residents in a street.
There are a total of 2020 households on this street, and the house numbers are numbered from 1 to 2020.
The method for Xiaolan to make the house plate is to make the numeric characters from 0 to 9 first, and finally paste the characters on the house plate as needed. For example, house plate 1017 needs to paste the characters 1, 0, 1, 7 in sequence, that is, 1 character 0 is needed. 2 characters 1, 1 character 7. How many characters 2 are needed to make all the number 1 to 2020?
Topic analysis
Violent search to determine whether the characters in each position meet the conditional
topic code

#include<iostream>
using namespace std;
int calu(int num)
{
    
    
	int ans = 0;
	while(num)
	{
    
    
		if(num%10==2)
			ans++;
		num/=10;
	}
	return ans;
}
int main()
{
    
    
	int cnt = 0;
	for(int i = 1; i <=2020; i++)
	{
    
    
		cnt+=calu(i);
	}
	cout << cnt <<endl;
	return 0;
} 

Question answer

624

Question 2: Restricted score

Title description
If the greatest common divisor of the numerator and denominator of a fraction is 1, the fraction is called a reduced fraction.
For example, 3/4, 5/2, 1/8, 7/1 are all reduced scores.
Excuse me, how many reduced fractions, whose numerator and denominator are both integers between 1 and 2020 (including 1 and 2020)?
Question analysis
Violent search, judge the question code by the greatest common divisor

#include<iostream>
using namespace std;

int gcd(int a,int b)
{
    
    
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
int main()
{
    
    
	int ans = 0;
	for(int i = 1; i <= 2020; i++)
	{
    
    
		for(int j = 1; j <= 2020; j++)
		{
    
    
			if(gcd(i,j)==1)
			{
    
    
				ans++;
			}
		}
	}
	cout << ans <<endl;
	return 0;
}

Question answer

2481215

Question 3: Serpentine fill in the number

Title description
As shown in the figure below, Xiaoming fills an infinite matrix with a "snake shape" of positive integers starting from 1.
1 2 6 7 15…
3 5 8 14…
4 9 13…
10 12…
11
…… It is
easy to see that the number in the second row and second column of the matrix is ​​5. What is the number in row 20 and column 20 in the matrix
?
Problem analysis:
You can rotate the graph 45 degrees clockwise, we can find that 20 rows and 20 columns should be located in the middle of the 49th layer, and then the simulation can be calculated

111
	  	      3 2
224 5 6
	        10 9 8 7
3311 12 13 14 15
.................

Topic code

#include<iostream>

using namespace std;

int main()
{
    
    
	//首先计算第20行20列位于三角形第几行,用公式算出是2*20-1=39行
	//计算39行的最后一个数 
	int n = 20;
	n = n*2-1;
	int ans = 0,sum =  0;
	for(int i = 1; i <=n ;i++)
	{
    
    
		sum+=i; 
	} 
	ans = (sum+sum-n+1)/2;
	cout << ans <<endl;
	return 0;
	 
} 

Question answer

761

Fourth question: 7-segment code

Title description
Xiaolan uses a seven-segment digital tube to represent a special kind of text.
Seven-segment code The figure above shows an icon of the seven-segment digital tube. There are 7 segments of light-emitting diodes in the digital tube, which are marked as a, b, c, d, e, f, g. Xiaolan chooses a part of the diode (at least one) to emit light to express characters. When designing the expression of characters, all light-emitting diodes are required to be connected in one piece.
For example: b is illuminated, other diodes do not emit light can be used to express a character.
For example: c light-emitting, other diodes not light-emitting can be used to express a character. This scheme and the scheme on the previous line can be used to represent different characters, although they look similar.
For example: a, b, c, d, e glow, f, g not glow can be used to express a character.
For example: b, f are luminous, other diodes are not luminous and cannot be used to express a character because the luminous diodes are not connected together.
Excuse me, how many different characters can Xiaolan express with a seven-segment digital tube?
Insert picture description here

Topic analysis
topic codes



Question 5: Plane segmentation

The title describes
how many parts can 20 circles and 20 straight lines divide a plane into?
Topic analysis
topic codes



Question 6: Performance Statistics

Topic description
Xiaolan organized an exam for the students. The total score is 100 points, and each student's score is an integer from 0 to 100. Please calculate the highest score, lowest score and average score for this exam.
[Input format]
The first line of input contains an integer n, which represents the number of people in the exam.
The next n lines, each line contains an integer from 0 to 100, representing a student's score.

[Output format]
Output three lines.
The first line contains an integer that represents the highest score.
The second line contains an integer that represents the lowest score.
The third line contains a real number, rounded to the nearest two decimal places, indicating an average score.

[Sample input]
7
80
92
56
74
88
99
10
[Sample output]
99
10
71.29
[Evaluation use case scale and conventions]
For 50% of evaluation use cases, 1 ≤ n ≤ 100.
For all evaluation use cases, 1 ≤ n ≤10000.
Topic analysis
topic codes



Question 7: Palindrome Date

The title describes that
during the 2020 Spring Festival, there is a special date that attracts everyone's attention: February 2, 2020. Because if this date is written as an 8-digit number in the format of "yyyymmdd", it is 20200202, which
happens to be a palindrome number. We call such a date a palindrome date.
Some people say that 20200202 is a special day of "one in a thousand years". Xiaoming disagrees with this, because less than 2 years later is the next palindrome date: 20211202, which is December 2, 2021.
Some people also said that 20200202 is not just a palindrome date, but an ABABBABA-type palindrome date. Xiao Ming also disagrees with this, because about 100 years later, he will encounter the next ABABBABA palindrome date: 21211212, which is December 12, 2121. It's not a "one encounter in a thousand years", but a "two encounters in a thousand years" at best.
Given an 8-digit date, please calculate the next palindrome date and the next ABABBABA palindrome date after the date.

[Input Format] The
input contains an eight-digit integer N, which represents the date.

[Output format]
Output two lines, each line has an eight-digit number. The first line represents the date of the next palindrome, and the second line represents the date of the next
ABABBABA palindrome.

[Sample input]
20200202
[Sample output]
20211202
21211212
[Evaluation use case scale and conventions]
For all evaluation use cases, 10000101 ≤ N ≤ 89991231, ensure that N is an 8-digit representation of a legal date.
Topic analysis
topic codes



Question 8: Substring score

Title description
For a string S, we define the score f(S) of S as the number of characters that appear exactly once in S. For example, f ("aba") = 1, f ("abc") = 3, f ("aaa") = 0.
Now given a string S[0...n-1] (length n), please calculate for all non-empty substrings S[i...j](0 ≤ i ≤ j <n), f (S[ What is the sum of i... j]).

[Input Format]
Input a line containing a string S composed of lowercase letters.

[Output format]
Output an integer to represent the answer.

[Sample input]
ababc
[Sample output]
21
[Sample description]
Substring f value:

a 1
ab 2
aba 1
abab 0
ababc 1
b 1
ba 2
bab 1
babc 2
a 1
ab 2
abc 3
b 1
bc 2
c 1
[Evaluation use case scale and convention]
For 20% of evaluation use cases, 1 ≤ n ≤ 10;
For 40% of the evaluation cases, 1 ≤ n ≤ 100;
for 50% of the evaluation cases, 1 ≤ n ≤ 1000;
for 60% of the evaluation cases, 1 ≤ n ≤ 10000;
for all evaluation cases, 1 ≤ n ≤ 100000.
Topic analysis
topic codes



Question 9: Desert Island Detection

Title description
Scientist Xiaolan came to a deserted island and prepared to conduct exploration and investigation on the deserted island. Xiaolan uses an ultrasonic positioning device to locate herself. In order to use this device, Xiaolan needs to install a fixed transmitter and a fixed receiver at different points. Xiaolan also has a mobile device in his hand. The positioning device needs to transmit a signal from the transmitter to the mobile device, and the mobile device will forward it immediately after receiving it, and finally receive it by the receiver. According to the time difference between these devices, it can calculate the distance between the mobile device and the transmitter and receiver. Distance to achieve positioning.
Xiaolan has installed the transmitter and receiver in two locations, where the transmitter is installed at coordinates (x A, y A) (x_A, y_A) (xA?,yA?), and the receiver is installed at coordinates (x B, y B) (x_B, y_B) (xB?,yB?). Xiaolan's transmitter and receiver may or may not be on the island. The design of Xiaolan's positioning device has some flaws. When the sum of the distance from the transmitter to the mobile device plus the distance from the mobile device to the receiver is greater than L, the positioning device does not work properly. When the sum is less than or equal to L, the positioning device works normally. For safety, Xiaolan only conducts surveys in areas where the positioning equipment works normally.
It is known that the desert island is a triangle, and the coordinates of the three vertices are (x 1, y 1) (x_1, y_1) (x1?,y1?), (x 2, y 2) (x_2, y_2) (x2? ,y2?), (x 3, y 3) (x_3, y_3) (x3?,y3?).
Please calculate, how much area can Xiaolan detect on the deserted island?

[Input format]
The first line of input contains five integers, which are x A, y A, x B, y B, L x_A, y_A, x_B, y_B, L xA?,yA?,xB?,yB?, L.
The second line contains six integers, namely x 1, y 1, x 2, y 2, x 3, y 3 x_1, y_1, x_2, y_2, x_3, y_3 x1?,y1?,x2?,y2?, x3?,y3?.

[Output format]
Output one line, including a real number, rounded to the nearest 2 decimal places, indicating the answer.
Taking into account the error in the calculation, you can score as long as your output differs from the reference output by no more than 0.01.

[Sample input]
10 6 4 12 12
0 2 13 2 13 15
[Sample output]
39.99
[Sample description]
When the output is 39.98, 39.99 or 40.00, you can score.
Topic analysis
topic codes



Tenth question: String sorting

Title description
Xiaolan recently learned some sorting algorithms, among which bubble sorting impressed him. In bubble sorting, only two adjacent elements can be exchanged at a time. Xiaolan found that if the characters in a string are sorted and only two adjacent characters are allowed to be exchanged, the total number of exchanges for bubble sorting is the least among all possible sorting schemes.
For example, for string lan sorting, only 1 exchange is required. For the string qiao sorting,
a total of 4 exchanges are required. Xiaolan found a lot of strings and tried to sort them. He happened to come across a string that needed V exchanges, but he forgot to write down this string, and he can't find it now.
Please help Xiaolan find a string that only contains lowercase English letters and no repetition of letters. Sorting the characters of this string requires exactly V exchanges. If you can find more than one, please tell Xiaolan the shortest one. If there are still multiple shortest ones, please tell Xiaolan the one with the smallest lexicographic order. Please note that the same characters can be included in the string.

[Input format]
The first line of input contains an integer V, a lucky number for Xiaolan.

[Output format]
A line of character string required by the title.

[Sample input]
4
[Sample output]
bbaa
[Evaluation use case scale and conventions] I
missed it but not saved.
Probably:
For 20% evaluation cases, 1 ≤ n ≤ 20;
For 50% evaluation cases, 1 ≤ n ≤ 100;
for 100% evaluation use cases, 1 ≤ n ≤ 10000; question code for
question analysis



Guess you like

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