Teachers have prepared an electronic printed version for everyone. Friends who need the complete electronic version can check at the end of the article.
【Answer Analysis】
1. Explanation: The answer is D.
In C++, the default access specifier for struct is public, while for class it is private. If you need to change this default behavior, you can explicitly declare members as private in a struct.
2. Explanation: The answer is B.
For detailed analysis, see the image below——
3. Explanation: The answer is C.
For detailed analysis, see the image below——
4. Explanation: The answer is D.
According to the addition principle, there are a total of 10 + 5 + 2 = 17 ways.
5. Explanation: The answer is A.
Performing DFS on a binary tree, releasing each node during the backtracking phase, has a time complexity of O(n).
6. Explanation: The answer is A.
For detailed analysis, see the image below——
A stricter proof is as follows, reiterating that this question is definitely beyond the syllabus——
7. Explanation: The answer is C.
For detailed analysis, see the image below——
8. Explanation: The answer is A.
The full permutation of 5 is 5! = 120.
9. Explanation: The answer is A.
The core property of Pascal's Triangle: except for the 1s at the beginning and end of each row, each number equals the sum of the two numbers directly above it. For detailed analysis, see the image below——
10. Explanation: The answer is C.
For detailed analysis, see the image below——
11. Explanation: The answer is D.
For detailed analysis, see the image below——
12. Explanation: The answer is B.
For detailed analysis, see the image below——
13. Explanation: The answer is B.
The essence of Floyd's algorithm is a DP, or can be understood as a relaxation operation: if the shortest path from i to j can be updated through an intermediate node k: then it requires map[i][j] > map[i][k] + map[k][j]; the correct answer is option B.
14. Explanation: The answer is A.
Merge sort is based on divide and conquer with a time complexity of O(n log n) and a space complexity of O(n).
Review and expansion of related knowledge points:
As of September of the exam year, the comparison of the characteristics of the top ten classic sorts can be found in the image below——
15. Explanation: The answer is B.
This question examines the time complexity of solving the Fibonacci sequence. The summary of the time complexity for the Fibonacci sequence is as follows: if solved using iteration or memoized search, the time complexity is O(n); if it is brute force recursion, the default time complexity is O(2^n), and then a more precise time complexity should be as follows. Choose the closest one when answering.
Review and expansion of related knowledge points:
As of June of the exam year, the relevant knowledge points regarding the Fibonacci sequence can be found in the image below——
【Answer Analysis】
1. Explanation: Incorrect.
The symbol '&' is typically used for bitwise operations, especially bitwise AND operations. The bitwise AND operation compares the binary values of two numbers bit by bit; if both bits are 1, the corresponding result bit is 1, otherwise it is 0.
The decimal ASCII value of the character '3' is 51, represented in binary as 110011, which is odd. The &1 operation takes the lowest bit of 51 in binary. The result is the number 1, not the character '1'.
Review and expansion of related knowledge points:
As of September of the exam year, the complete ASCII code reference table can be found in the image below——
As of September of the exam year, relevant knowledge points regarding bitwise operations can be referenced in the image below——
2. Explanation: Incorrect.
Variables can be defined as both local and global variables.
3. Explanation: Incorrect.
Among the top ten classic sorts, the comparison-based sorts that are unstable are only four: Shell, Selection, Quick, and Heap; the rest are stable.
Review and expansion of related knowledge points:
As of September of the exam year, the comparison of the characteristics of the top ten classic sorts can be found in the image below——
4. Explanation: Correct.
For detailed analysis, see the image below——
5. Explanation: Incorrect.
The trigonometric functions in the math library, including the cos function, accept angle parameters in radians. Therefore, if you want to use degrees (like 60 degrees) as a parameter, you need to convert it to radians first. In C or C++, you can use M_PI (defined in math.h or cmath) to represent π, thus converting 60 degrees to radians, i.e., 60 * M_PI / 180.
6. Explanation: Correct.
Manually simulating is the simplest and most direct method, 7 + 5 + 5 + 5 + 5 = 27 in total with 5 coins, and there is no better solution.
7. Explanation: Incorrect.
For detailed analysis, see the image below——
8. Explanation: Correct.
The code a/2.0*b will automatically be implicitly converted to double type during execution, ensuring the correctness of the result.
Review and expansion of related knowledge points:
As of September of the exam year, relevant knowledge points regarding implicit conversion of data types can be found in the image below——
9. Explanation: Correct.
The formula calculation is direct, unrelated to scale, with a complexity of O(1).
10. Explanation: Correct.
This tests reasoning ability; based on the question's inquiry, the liar would answer the road to the honest country, and the honest person would also answer the road to the honest country, so the other road must lead to the liar's country.
GESP September 2024 C++ Level 8 Pairing Gloves
#include <bits/stdc++.h>using namespace std;
const long long mod=1e9+7;// Define modulus
long long t,n,m,k,c[2005][2005],f[2005];// Upper limit 2000, sufficient, c is the combination number, f is the power of 2
int main() {
cin>>t;
for(int i=0;i<=2000;i++) {
c[i][0]=1;
c[i][i]=1;
for(int j=1;j<i;j++) {
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;// Pascal's triangle formula
}
}
f[0]=1;
for(int i=1;i<=2000;i++) {
f[i]=f[i-1]*2%mod;// Preprocessing power of 2
}
while(t--)// Multiple tests
{
cin>>n>>m>>k;
if(k>n||m<2*k) cout<<0<<endl;// First judge insufficient k pairs
else {
cout<<c[n][k]*c[n-k][m-2*k]%mod*f[m-2*k]%mod<<endl;// Based on conclusion
}
}
return 0;
}
Code Idea——

<img alt="GESP: September 2024 C++ Level 8 Exam Questions and Solutions" src="https://boardor.com/wp-content/uploads/2026/01/0b0e95ed-a418-42c2-9c2c-e13cd17ce179.png" />
GESP September 2024 C++ Level 8 Beautiful Path
#include<bits/stdc++.h>using namespace std;
int a[100005];
vector<int> mp[100005];
int dp[100005];
int maxn=1;
void dfs(int x,int f){
vector<int> v; // I don't want to write max and second max, just use a vector to sort, the first two elements represent max and second max
dp[x]=1;
for(int i:mp[x]){
if(i==f) continue;
dfs(i,x);
if(a[i]!=a[x]){
dp[x]=max(dp[x],dp[i]+1);
v.push_back(dp[i]);
}
}
sort(v.begin(),v.end(),greater<int>());
if(v.size()==0) return ; // Special case for leaf nodes
if(v.size()==1) maxn=max(maxn,v[0]+1); // Special case for only one beautiful path starting from the i-th point, +1 indicates the i-th point itself, v stores without the i-th point itself, otherwise, it would count the i-th point twice, so we need to subtract 1
else maxn=max(maxn,v[0]+v[1]+1);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
mp[u].push_back(v);
mp[v].push_back(u); // Build bidirectional graph, the problem gives an unrooted tree
}
dfs(1,0);
cout<<maxn;
return 0;
}
Code Idea——
Learning Path——
Friends who need a watermark-free PDF format file are welcome to scan the QR code below to add friends for consultation.
▍ Declaration: This article is compiled from the internet. If there is any infringement, please contact us for deletion.
This public account publishes this article for the purpose of legally and reasonably sharing and disseminating information, expanding the audience range, promoting academic exchange, and advancing mutual progress. The public account holder solemnly declares that the publication of this article will strictly comply with relevant regulations and laws, will not infringe on any potential author's rights, and will not change the intent and content of the original text (if any). If there are any errors in source attribution or infringement of your legitimate rights and interests, please feel free to contact us for negotiation, contact (QQ): 993225721, and we will promptly correct or delete it.
If this article is fortunate enough to be reprinted, first, the public account holder thanks the reprint person for providing valuable information and knowledge for readers. We hope the article can be more widely disseminated and exchanged on the platform where it is reprinted; secondly, the reprint person should fully consider the potential risks and responsibilities that the reprint action itself may bring, including but not limited to legal responsibilities arising from infringement of intellectual property rights and infringement of others' rights and interests, ensuring the legal dissemination and use of this article. At the same time, I am also very willing to cooperate with the reprint person to understand, pay attention to, avoid, and eliminate relevant potential risks during the reprint process. If the reprint person has any relevant doubts, they are also welcome to contact us for negotiation, contact (QQ): 993225721.
We hope you follow us——