Learn programming with Lao Ma by “leveling up and fighting monsters”!
- Involves examination: Computer Society Programming Ability Level Certification (GESP)
- Activity content: Provides real exam questions of different levels for students to practice
- Preparation advice: Choose corresponding questions based on your preparation level
- Additional value: Can be used as preparation training for whitelist competitions
- This month’s check-in: Check-in questions
Day 01: GESP Level 1 2023.12_Xiao Yang’s Exam
[Submit]
https://www.luogu.com.cn/problem/B3921
[Problem Description]
Today is day , Xiao Yang has days left until the exam, can you calculate what day of the week Xiao Yang’s exam will be? (In this problem, represents Sunday)
[Input Description]
Input consists of 2 lines, the first line contains an integer (); the second line contains an integer ().
[Output Description]
Output an integer representing what day of the week Xiao Yang’s exam will be.
[Special Reminder]
In regular programs, it is good practice to provide prompts for input and output. However, in this exam, due to system limitations, please do not include any prompt information in the input and output.
[Sample Input 1]
1
6
[Sample Output 1]
7
[Sample Explanation 1]
Today is day 1, so 6 days later will be Sunday, which is represented by .
[Sample Input 2]
5
3
[Sample Output 2]
1
[Sample Explanation 2]
Today is day 5, so 3 days later will be day 1.
Reference Answer:
Method 1:
/*
* [GESP202312 Level 1] Xiao Yang's Exam
* https://www.luogu.com.cn/problem/B3921
*/
# include
using namespace std;
int main()
{
int X, N;
cin >> X >> N;
int a = (X + N) % 7;
cout << (a == 0 ? 7 : a);
return 0;
}
Method 2:
/*
* [GESP202312 Level 1] Xiao Yang's Exam
* https://www.luogu.com.cn/problem/B3921
*/
# include
using namespace std;
int main()
{
int X, N;
cin >> X >> N;
int a = (X - 1 + N) % 7 + 1;
cout << a;
return 0;
}
Day 01: GESP Level 2 2025.03_Arithmetic Matrix
[Submit]
https://www.luogu.com.cn/problem/B4259
[Problem Description]
Xiao A wants to construct a row column matrix such that each row and each column is an arithmetic sequence. Xiao A found that filling the integer in the row and the column can satisfy the requirement. Can you help Xiao A output this matrix?
[Input Description]
One line, two positive integers .
[Output Description]
A total of rows, each row contains integers separated by spaces, representing the matrix that Xiao A needs to construct.
[Sample Input 1]
3 4
[Sample Output 1]
1 2 3 4
2 4 6 8
3 6 9 12
[Data Range]
For all test points, it is guaranteed that ,.
Reference Answer:
/*
* [GESP202503 Level 2] Arithmetic Matrix
* https://www.luogu.com.cn/problem/B4259
*/
#include
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cout << i * j << " ";
}
cout << endl;
}
return 0;
}
Day 01: GESP Level 3 2025.09_Array Zeroing
[Submit]
https://www.luogu.com.cn/problem/B4413
[Problem Description]
Xiao A has an array consisting of non-negative integers. He will repeatedly perform the following operations on the array until all integers in the array become . In one operation, Xiao A will complete the following three steps:
- Find the largest integer in the array, denote its index as . If there are multiple maximum values, choose the one with the largest index.
- Find the smallest integer among all integers in the array that are not zero.
- Subtract the integer found in the first step by the integer found in the second step.
For example, the array needs to be transformed into after operations:
Xiao A wants to know how many operations are needed to make all integers in the array become . It can be proven that all integers in the array can eventually become after a finite number of operations. Can you help him calculate the answer?
[Input Description]
The first line contains a positive integer , representing the length of the array.
The second line contains non-negative integers, representing the integers in the array.
[Output Description]
One line, a positive integer, representing the number of operations needed to make all integers in the array become .
[Sample Input 1]
3
2 3 4
[Sample Output 1]
7
[Sample Input 2]
5
1 3 2 2 5
[Sample Output 2]
13
[Data Range]
For all test points, it is guaranteed that ,.
Reference Answer:
Typical simulation algorithm
Given a non-negative integer array, repeatedly perform the following operations until the array is all zeros:
- Find the maximum element (if there are multiple maximums, choose the one with the largest index)
- Find the minimum among all non-zero elements
- Subtract the maximum element by this minimum
Directly execute the three steps as described in the problem, recording the count until all are zero.
/*
* [GESP202509 Level 3] Array Zeroing
* https://www.luogu.com.cn/problem/B4413
*/
# include
using namespace std;
int main()
{
int arr[105];
int n, sum = 0, cnt = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
}
while (sum > 0)
{
int max = 0, min = 100, index = -1;
for (int i = 0; i < n; i++)
{
if (arr[i] >= max)
{
max = arr[i];
index = i;
}
if (arr[i] != 0 && arr[i] < min)
{
min = arr[i];
}
}
arr[index] -= min;
sum -= min;
cnt += 1;
}
cout << cnt << endl;
return 0;
}
Day 01: GESP Level 4 2025.06_Sorting
[Submit]
https://www.luogu.com.cn/problem/B4361
[Problem Description]
In physical education class, there are students lined up, the height of the th student is , and the weight is . The current lineup looks uneven, and the teacher hopes that the students can line up in order of height from tallest to shortest, and if the height is the same, then by weight from heaviest to lightest. During the adjustment of the lineup, only adjacent students can be swapped. The teacher wants to know the minimum number of swap operations needed to adjust the lineup to the target order.
[Input Description]
The first line contains a positive integer , representing the number of students.
The next lines, each containing two positive integers and , representing the height and weight of the th student.
[Output Description]
Output one line, an integer representing the minimum number of swaps needed.
[Sample Input 1]
5
1 60
3 70
2 80
4 55
4 50
[Sample Output 1]
8
[Sample Input 2]
5
4 0
4 0
2 0
3 0
1 0
[Sample Output 2]
1
[Data Range]
For all test points, it is guaranteed that ,.
Reference Answer:
/*
* [GESP202506 Level 4] Sorting
* https://www.luogu.com.cn/problem/B4361
*/
#include
using namespace std;
struct student
{
int h;
int w;
};
student arr[3005];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i].h >> arr[i].w;
}
int cnt = 0;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j].h < arr[j + 1].h)
{
cnt++;
student temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
else if(arr[j].h == arr[j + 1].h)
{
if (arr[j].w < arr[j + 1].w)
{
cnt++;
student temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
cout << cnt;
return 0;
}
Day 01: Openjudge 1.11.10_River Jumping
[Submit]
http://noi.openjudge.cn/ch0111/10/
[Description]
Every year, cows hold various special versions of jumping competitions, including jumping from one rock to another in the river. This exciting activity takes place in a long straight river, with a rock at the starting point and another rock at the endpoint, which is far from the starting point. Between the starting point and the endpoint, there are rocks, each with a distance from the starting point of .
During the competition, cows take turns starting from the starting point, trying to reach the endpoint, and can only jump from one rock to another. Of course, cows that are not strong enough cannot achieve the goal.
Farmer John is proud of his cows and has watched this competition every year. However, over time, he became very bored watching the timid cows slowly move between rocks that are very close together. He plans to remove some rocks so that the longest possible shortest jump distance from the starting point to the endpoint is maximized. He can remove at most rocks, excluding the starting and ending points.
Please help John determine what the longest possible shortest jump distance is after removing these rocks.
[Input]
The first line contains three integers , separated by a single space.
The next lines each contain an integer representing the distance of each rock from the starting point. The rocks are given in order of distance from the starting point, and no two rocks will be at the same position.
[Output]
One integer, representing the longest possible shortest jump distance.
[Sample Input]
25 5 2
2
11
14
17
21
[Sample Output]
4
[Hint]
After removing the rocks at 2 and 14, the shortest jump distance is 4 (from 17 to 21 or from 21 to 25).
[Reference Program]
Problem: In a segment of length , there are points, remove points, leaving points, dividing the entire segment into segments. Find the maximum of the minimum segment length among all possible partition schemes.
If the minimum distance between given points is , that is, the distance between points must be .
To satisfy the condition: check if there exists a scheme where the minimum segment length is .
- If the number of points removed is less than or equal to , then there exists a scheme where the minimum segment length is , the condition is satisfied.
- If the number of points removed is greater than , then there is no such scheme, the condition is not satisfied.
Once the condition to check is clear, this becomes a binary search problem to find the maximum value that satisfies a certain condition.
Find the midpoint: mid = (l + r)/2;
- If satisfies the condition, the next should be larger, take the right half, l = mid + 1;
- If does not satisfy the condition, the next should be smaller, take the left half, r = mid – 1;
The final result is the maximum of the minimum segment length among all schemes.
/*
* 10: River Jumping
* http://noi.openjudge.cn/ch0111/10/
*/
#include
using namespace std;
const int N = 50005;
int arr[N];
int l, n, m;
bool check(int x)
{
int t = 0, num = 0; // t: current observation point position
for (int i = 1; i <= n; i++)
{
if (arr[i] - t < x)
{
num++;
}
else
{
// If the distance from point i to the current observation point is greater than or equal to x, then i's position is the current observation point
t = arr[i];
}
}
if (l - t < x)
{
// If the distance from the endpoint to the observation point is less than x, then remove the observation point
num++;
}
// Check if the number of removed points is less than or equal to M
return num <= m;
}
int main()
{
cin >> l >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
int le = 0, ri = l, mid;
while (le + 1 < ri)
{
mid = (le + ri) / 2;
if (check(mid))
{
le = mid;
}
else
{
ri = mid;
}
}
cout << le;
return 0;
}
Day 01: Openjudge 3.6.1758_Binary Tree
[Submit]
http://noi.openjudge.cn/ch0306/1758/
[Description]

As shown in the figure above, a binary tree is composed of positive integers. There is a unique path from any node to the root node (the node numbered 1), for example, the path from 10 to the root node is , and the path from 4 to the root node is . The path from the root node 1 to itself contains only one node, which is 1, so the path is . For two nodes and , assuming their paths to the root node are and (here clearly ), there must exist two positive integers and such that starting from and , there are , , , . Now the problem is, given and , find (which is ).
[Input]
The input consists of a single line containing two positive integers and , both of which do not exceed 1000.
[Output]
The output consists of a single positive integer .
[Sample Input]
10 4
[Sample Output]
2
[Reference Program]
/*
* 1758: Binary Tree
* http://noi.openjudge.cn/ch0306/1758/
*/
#include
#include
using namespace std;
int main()
{
stack st1, st2;
int x, y;
cin >> x >> y;
while (x != 0)
{
st1.push(x);
x = x / 2;
}
while (y != 0)
{
st2.push(y);
y = y / 2;
}
int ans = 1;
while (!st1.empty() && !st2.empty())
{
if (st1.top() == st2.top())
{
ans = st1.top();
}
st1.pop();
st2.pop();
}
cout << ans << endl;
return 0;
}
Youth Programming Competition Exchange
The “Youth Programming Competition Exchange Group” has been established (suitable for youth aged 6 to 18), add the assistant’s WeChat to invite everyone into the learning group. After joining the group, everyone can participate in regularly organized 21-day problem-solving check-ins, level exam assessments, Ministry of Education whitelist competition coaching, and youth programming team competitions.
