[Blue Bridge Cup Sprint] The 12th Provincial Competition of the Blue Bridge Cup Group C++b Real Questions-Fill in the Blank Questions

Table of contents

Question A: Space

problem solving ideas

Answer

Question B: Cards

problem solving ideas

Answer

Question C: Straight line

problem solving ideas

Answer

Test Question D: Cargo Arrangement

problem solving ideas

Answer

Question E: Path

problem solving ideas

Answer

​edit

Write at the end:


Question A: Space

Xiaolan is going to open an array with 256 MB of memory space,

Each element of the array is a 32-bit binary integer,

If the space occupied by the program and the auxiliary space required for maintaining memory are not considered,

How many 32-bit binary integers can be stored in 256 MB?

problem solving ideas

1MB = 1024 * 1024 bytes

1 byte = 8 bits

You can use the calculator that comes with your computer to calculate:

(256 * 1024 * 1024) / (32 / 8) = 67108864

Answer

67108864

Question B: Cards

Xiaolan has a lot of number cards, and each card is the number 0 to 9.

Xiaolan is going to use these cards to spell some numbers, he wants to spell positive integers starting from 1,

Every time one is spelled, it is saved, and the card cannot be used to spell other numbers.

Xiaolan wants to know how much she can spell from 1.

For example, when Xiaolan has 30 cards, including 3 cards from 0 to 9, Xiaolan can spell out 1 to 10,

But when spelling 11, there is only one card 1 , which is not enough to spell 11.

Now Xiaolan has 2021 cards from 0 to 9 in his hand, a total of 20210 cards. How many cards can Xiaolan get from 1?

Tip: It is recommended to use computer programming to solve the problem.

problem solving ideas

My idea for this question is violent enumeration.

It is not difficult to imagine by looking at the question, 1 must be the most used number (I also marked it in the question)

So we only need to use up all the cards enumerated to 1, and jump out when the next number needs 1:

#include <iostream>
using namespace std;

int main() {
	int cnt = 2021;
	int res = 0;
	for (int i = 0; ; i++) {
		int t = i;
		while (t) {
			if (t % 10 == 1) {
				cnt--;//卡片用的个数
			}
			t /= 10;
		}
		if (cnt < 0) {
			break;//如果这个数要用,直接跳出循环
		}
		else if (cnt == 0) {
			res = i;//如果卡片用完,就更新需要返回的值
		}
	}
	cout << res << endl;
	return 0;
}

Answer

3181

Question C: Straight line

In a plane Cartesian coordinate system, two points can define a straight line.

If there are multiple points on a straight line, then the straight line determined by any two of these points is the same.

Given 2 × 3 integer points on the plane { ( x , y ) ∣ 0 ≤ x < 2 , 0 ≤ y < 3 , x ∈ Z , y ∈ Z },

That is, the abscissa is an integer between 0 and 1 (including 0 and 1), 

A point whose ordinate is an integer between 0 and 2 (inclusive)

A total of 11 different straight lines are determined by these points.

Given 20 × 21 integer points on the plane { ( x , y ) ∣ 0 ≤ x < 20 , 0 ≤ y < 21 , x ∈ Z , y ∈ Z },

That is, the abscissa is an integer between 0 and 19 (including 0 and 19 ),

The ordinate is an integer point between 0 and 20 (inclusive).

May I ask how many different straight lines are determined by these points?

problem solving ideas

Don't ask, if you ask, you can't do it.

Answer

40257

Test Question D: Cargo Arrangement

Xiaolan has an oversized warehouse that can store a lot of goods.

Now, Xiaolan has n boxes of goods to be placed in the warehouse, and each box of goods is a regular cube.

Xiaolan stipulates three mutually perpendicular directions of length, width, and height. The sides of each box of goods must be strictly parallel to the length, width, and height.

Xiaolan hopes that all the goods will eventually be arranged in one big cube.

That is, stack L , W , and H goods in the directions of length, width, and height, satisfying n = L × W × H .

Given n, how many schemes for stacking goods meet the requirements.

For example, when n = 4, there are the following 6 schemes:

1 × 1 × 4 、1 × 2 × 2 、1 × 4 × 1 、2 × 1 × 2 、2 × 2 × 1、4 × 1 × 1 。

Excuse me, when n = 2021041820210418 (note that there are 16 digits),

How many options are there in total?

Tip: It is recommended to use computer programming to solve the problem.

problem solving ideas

My idea is to find all divisors of n,

Then violently enumerate the number of his schemes:

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

typedef long long ll;

int main() {
	vector<ll> v;
	ll n = 2021041820210418;
	//这里是取n的所有约数
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			v.push_back(i);
			if (n / i != i) v.push_back(n / i);
		}
	}
	int res = 0;
	for (auto a : v) {
		for (auto b : v) {
			for (auto c : v) {
				if (a * b * c == n) res++;
			}
		}
	}
	cout << res << endl;
	return 0;
}

Answer

2430

Question E: Path

Xiaolan was very happy after learning the shortest path. He defined a special graph and hoped to find the shortest path in the graph.

Xiaolan's graph consists of 2021 nodes, numbered 1 to 2021 in sequence.

For two different nodes a , b

If the absolute value of the difference between a and b is greater than 21,

Then there is no edge connection between the two nodes;

If the absolute value of the difference between a and b is less than or equal to 21,

Then there is an undirected edge whose length is the least common multiple of a and b between the two points.

For example: there is no edge connection between node 1 and node 23;

There is an undirected edge between node 3 and node 24 with a length of 24;

There is an undirected edge with length 75 between node 15 and node 25 .

Please calculate, what is the shortest path length between node 1 and node 2021.

Tip: It is recommended to use computer programming to solve the problem.

problem solving ideas

won't do. . . Woohoo. . .

Answer

10266837

Write at the end:

The above is the content of this article, thank you for reading.

If you like this article, please like and comment, and write down your opinions.

If you want to learn programming with me, you might as well follow me, we will learn and grow together.

I will output more high-quality content in the future, welcome to watch.

Guess you like

Origin blog.csdn.net/Locky136/article/details/129908151