2020 11th C/C++ Group A Second Blue Bridge Cup Provincial Match

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: Making the Door Sign

Topic Description
Xiao Lan wants to make house numbers for the residents of a street.
This street has a total of 2020 residents, with house numbers from 1 to 2020.
The method of Xiaolan to make the house number is to first make the number characters from 0 to 9, and finally paste the characters on the house number as needed. For example, the house number 1017 needs to paste the characters 1, 0, 1, and 7 in sequence, that is, one character 0 is required. 2 characters 1, 1 character 7. How many characters 2 are needed in total 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: Estimated Fractions

Problem 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 fractions.
Excuse me, how many fractions are there, with both the numerator and denominator being integers between 1 and 2020 (including 1 and 2020)?
Topic analysis
Violent search, judge the
topic 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 Filling in Numbers

Question Description
As shown in the figure below, Xiao Ming fills an infinite matrix with a positive integer "snake" 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. Can you count the number in the 20th row and 20th column
of the matrix?
Topic analysis
The graph can be rotated 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

Question 4: 7-segment code

Title description
Xiaolan uses a seven-segment digital tube to represent a special type of text.
Seven-segment code The figure above shows an illustration of the seven-segment code 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 has to choose a part of the diodes (at least one) to emit light to express the characters. When designing the expression of the characters, all the light-emitting diodes are required to be connected together.
For example: b emits light, other diodes do not emit light can be used to express a character.
For example: c emits light, other diodes do not emit light 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 illuminated, f, g not illuminated can be used to express a character.
For example: b, f emit light, other diodes do not emit light and cannot be used to express a character, because the light emitting diodes are not connected together.
Excuse me, how many different characters can Xiaolan express with a seven-segment digital tube?
insert image description here

topic analysis
topic code



Question 5: Plane Segmentation

Question Description
How many parts can a plane be divided into at most by 20 circles and 20 lines?
topic analysis
topic code



Question 6: Score Statistics

Item description
Xiaolan organized an exam for the students, with a total score of 100 points, and each student's score was an integer from 0 to 100. Please calculate the highest, lowest and average scores for this exam.
【Input format】
The first line of input contains an integer n, which represents the number of people to be tested.
The next n lines, each containing an integer from 0 to 100, represent a student's score.

【Output format】
Output three lines.
The first line contains an integer representing the highest score.
The second line contains an integer representing the lowest score.
The third line contains a real number, rounded to exactly two decimal places, representing the average score.

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



Question 7: Date of Palindrome

Title Description
During the Spring Festival in 2020, there is a special date that caught everyone's attention: February 2, 2020. Because if this date is written in the format of "yyyymmdd" as an 8-digit number, it is 20200202,
which happens to be a palindrome. We call such dates a palindrome date.
Some people say that 20200202 is a special day "once in a thousand years". Xiao Ming disagrees with this very much, because less than 2 years later will be the next palindrome date: 20211202, which is December 2, 2021.
Some people also said that 20200202 is not just a palindrome date, but a palindrome date of the ABABABA type. Xiao Ming also disagrees with this, because in about 100 years, the next palindrome date of the ABABABA type will be encountered: 21211212, which is December 12, 2121. It's not "once in a thousand years", but at most "twice in a thousand years".
Given an 8-digit date, please calculate which day is the next palindrome date and the next palindrome date of type ABABABA after the date.

【Input format】The
input contains an eight-digit integer N, which represents the date.

【Output format】
Output two lines, each line contains one eight-digit number. The first line represents the date of the next palindrome, and the second line represents the date of the next palindrome of
type ABABABA.

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



Question 8: Substring Score

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

【Input format】
Enter a line containing a string S consisting 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
[Scale and convention of evaluation cases]
For 20% of evaluation cases, 1 ≤ n ≤ 10;
For 40% of evaluation cases, 1 ≤ n ≤ 100;
for 50% of evaluation cases, 1 ≤ n ≤ 1000;
for 60% of evaluation cases, 1 ≤ n ≤ 10000;
for all evaluation cases, 1 ≤ n ≤ 100000.
topic analysis
topic code



Question 9: Desert Island Detection

Topic description
Scientist Xiao Lan came to a deserted island, ready to conduct exploration and investigation on this deserted island. Xiaolan used an ultrasonic positioning device to locate himself. In order to use this device, Xiaolan needs to install a fixed transmitter and a fixed receiver at different points. There is also a mobile device in Xiaolan's hand. The positioning device needs to transmit a signal from the transmitter to the mobile device. After the mobile device receives it, it will be forwarded immediately, and finally received by the receiver. According to the time difference between these devices, the distance between the mobile device and the transmitter can be calculated. distance to achieve positioning.
Xiaolan has installed the transmitter and receiver in two positions, 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?). Little Blue's transmitter and receiver may or may not be on the island. There are some flaws in the design of Xiaolan's positioning device. 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 fine. For safety, Xiaolan only probes and investigates 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 big is the area that Xiaolan can detect on the desert island?

【Input format】
The first line of input contains five integers, namely 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, 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 a line, including a real number, rounded to 2 decimal places, indicating the answer.
To account for errors in calculations, you can score as long as your output does not differ by more than 0.01 from the reference output.

[Sample input]
10 6 4 12 12
0 2 13 2 13 15
[Sample output]
39.99
[Sample description]
You can score when the output is 39.98, 39.99 or 40.00.
topic analysis
topic code



Question 10: String Sorting

Topic description
Xiaolan recently learned some sorting algorithms, among which bubble sort impressed him a lot. In bubble sort, only two adjacent elements can be swapped at a time. Xiaolan found that if the characters in a string are sorted and only two adjacent characters are allowed to be swapped, the total number of swaps in bubble sort is the least among all possible sorting schemes.
For example, for string lan ordering, only 1 exchange is required. For string qiao sorting,
a total of 4 swaps 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 the string and can't find it now.
Please help Xiaolan to find a string that contains only lowercase English letters and no repeated letters. Sorting the characters of this string requires exactly V exchanges. If it is possible to find more than one, please tell Xiaolan the shortest one. If there are still more than one shortest, please tell Xiaolan the one with the smallest lexicographical order. Note that strings can contain the same characters.

【Input format】
The first line of input contains an integer V, the lucky number of the little blue.

[Output format]
One line of string required by the question.

[Sample input]
4
[Sample output]
bbaa
[Evaluation use case scale and convention] Missed and
not saved
Approximately:
for 20% of the evaluation use cases, 1 ≤ n ≤ 20;
for 50% of the evaluation use cases, 1 ≤ n ≤ 100;
for 100% of the evaluation use cases, 1 ≤ n ≤ 10000;
Item Analysis
Item Code



Guess you like

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