April 2022 Blue Bridge Cup Software Provincial Competition: Zhenti + Analysis


Question A

Question A: Converting from Nine to Decimal
The total score for this question: 5 points
[Problem description]
Nine positive integer ( 2022 ) 9 (2022)_9(2022)9Convert to decimal equal to what?

Parsing:
( 2022 ) 9 = 2 ∗ 9 3 + 2 ∗ 9 1 + 2 ∗ 9 0 = 1478 (2022)_9=2*9^3+2*9^1+2*9^0=1478(2022)9=293+291+290=1478

Answer:
1478


Question B

Question B: Date of Shunzi
Total score of this question: 5 points
[Problem description]
Xiao Ming likes Shunzi very much. A straight refers to three consecutive numbers: 123, 456, etc. A straight date refers to a date in which any consecutive three-digit number is a straight in the yyyymmdd notation of a date. For example, 20220123 is a straight date, because it appears a straight: 123; while 20221023 is not a straight date, it does not have a straight. Xiao Ming wants to know how many Shunzi dates there are in the entire 2022 year.

Analysis:
This question tests the reasoning ability. Since the year has already been determined, it is only necessary to judge whether the 2022mmdd contains a straight.

  • There are 12 values ​​for mm, namely 01~12. Only 01, 11 and 12 are eligible, and straights are not possible in other months.
  • For 2022-01-dd, only 2022-01-23 is eligible
  • For 2022-11-dd, only 2022-11-23 is eligible
  • For 2022-12-dd, only 2022-12-30 and 2022-12-31 are eligible

Answer:
So the answer is: 4


Question C

Question C: Statistics
Time Limit: 1.0s Memory Limit: 256.0MB Total score for this question: 10 points
[Problem description]
Xiao Ming decided to start working hard to prepare for the Blue Bridge Cup competition from next Monday. He plans to do problem a every day from Monday to Friday, and problem b every day on Saturday and Sunday. Please help Xiao Ming calculate, according to the plan, in which day will he achieve the number of questions greater than or equal to n?
【Input format】The
input line contains three integers a, b and n.

Analysis: This question is a sub-question, which can be solved by using a while loop.

Answer:

#include<iostream>
using namespace std;

int main() {
    
    
	int a = 0, b = 0, n = 0;
	cin >> a >> b >> n;
	int day = 0;

	while (n > 0) {
    
    
		day++;
		if (day % 7 == 0 || day % 7 == 6) //周六、周天
			n -= b;
		else
			n -= a;
	}
	cout << day << endl;
	return 0;
}

Question D

Question D: Pruning shrubs
Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 10 points
[Problem description]
Alice wants to complete a task of pruning shrubs.
There are N shrubs neatly lined up from left to right. Alice prunes a shrub every evening so that the height of the shrub becomes 0 cm. Alice's order of pruning shrubs is to start with the leftmost shrub and prune one shrub to the right each day. When the rightmost shrub has been trimmed, she will turn around and start trimming the shrub to the left the next day. Turn direction again until the leftmost shrub has been trimmed. And so on and so forth.
The bush will grow 1 cm tall from morning to evening and not the rest of the time. On the morning of the first day, the height of all shrubs is 0 cm. Alice wants to know how tall each bush can grow.

Analysis:
This question can be deduced by simulation to get the maximum length of each shrub. Suppose these N shrubs are: n 1 n_1n1 n 2 n_2 n2、…、 n N n_N nN

  • with n 1 n_1n1For example, the highest time is when Alice has just completed a cycle (that is, from left to right, and from right to the leftmost end), and the height at this time is 2(N-1).
  • for n 2 n_2n2, in a left-to-right process, n 2 n_2n2than n 1 n_1n1Cut one day later; n 2 n_2 in the process from right to leftn2than n 1 n_1n1cut one day earlier; so n 2 n_2n2than n 1 n_1n12 cm lower, so n 2 n_2n2The maximum height is: 2(N-2)
  • And so on, when i<=N/2, ni n_iniThe maximum height of is: 2(Ni)
  • When i>N/2, it forms a symmetric relationship with i<N/2, which can be obtained by direct simulation: 2 ∗ ( i − 1 ) 2 * (i - 1)2(i1)

Answer:

#include<iostream>
using namespace std;

int main() {
    
    
	int N = 0;
	cin >> N;
	int height = 0;
	for (int i = 1; i <= N; i++) {
    
    
		if (i <= N / 2) {
    
    
			height = 2 * (N - i);
		}
		else {
    
    
			height = 2 * (i - 1);
		}
		cout << height << endl;
	}
	return 0;
}

Question E

Question E: X-base subtraction
Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points
[Problem description] The
base system specifies how many digits are added to each other.
X base is a very magical base, because the base of each digit is not fixed! For example, say a certain X base number, the lowest digit is binary, the second digit is decimal, and the third digit is octal, then the X base number 321 is converted to a decimal number of 65.
Now there are two integers A and B represented by X base, but the base of each digit is still uncertain, only know that A and B are the same base rule, and each digit is up to N base, and the lowest is binary. Please calculate the smallest possible result of AB.
Please note that you need to ensure that A and B are legal in base X, that is, the number on each digit


Question F

Question F: Counting sub-matrices
Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points
[Problem description]
Given an N×M matrix A, please count how many sub-matrices (minimum 1×1, maximum NxM) satisfy that the sum of all numbers in the submatrix does not exceed the given integer K?
[Input format]
The first line contains three integers N, M and K.
The next N lines each contain M integers, representing matrix A.

Parse:


Question G


Question H


Question I


Question J


Note: The answers in this article are for reference only. This article is constantly being updated. It is recommended that you collect it!

Guess you like

Origin blog.csdn.net/wjinjie/article/details/124060707