The 14th Blue Bridge Cup (Phase 3) Simulation Competition Test Questions and Solution C++

The 14th Blue Bridge Cup (Phase 3) Simulation Competition Test Questions and Solution C++

Question A

【Problem Description】

Please find the smallest number greater than 2022 that, when converted to hexadecimal, has all digits (without leading 0s) as letters (A to F).
 Please submit the decimal form of this number as an answer.

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.

Problem solution: base conversion

Continuously use the remainder and division to determine whether each digit after converting to hexadecimal is > 9

When formatting the output, the %x placeholder can convert the integer into a hexadecimal output. If it doesn’t work, you can output it again and use your eyes to find it.

// 答案:2730
#include <bits/stdc++.h>
using namespace std;

bool check(int x) {
    
    
	while (x) {
    
    
		if (x % 16 <= 9) return false;
		x /= 16;
	}
	return true;
}

int main() {
    
    
	int ans = 2023;
	while (!check(ans)) {
    
    
		printf("%d --> %x\n", ans, ans);
		ans ++;
	}
	printf("%d --> %x\n", ans, ans);
	cout << ans << endl;
	return 0;
}

Question B

【Problem Description】

In Excel, column names use a combination of English letters. The first 26 columns use one letter, in order from A to Z, and the next 26*26 columns use a combination of two letters, in order from AA to ZZ.
 What is the name of column 2022?

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is a string composed of uppercase letters. When submitting the answer, only fill in this string. If you fill in the extra content, you will not get points.

Problem solution: Simulate carry

Simulate each bit with an array, the carry is not equal to the 26 carry, but greater than the 26 carry and subtract 26 from the current bit

// 答案:byt
#include <bits/stdc++.h>
using namespace std;

int a[10];

void output() {
    
    
	for (int i = 9; i >= 0; i --) {
    
    
		if (a[i]) 
			cout << char(a[i] - 1 + 'A');
	}
	cout << endl;
}

int main() {
    
    
	for (int i = 1; i <= 2022; i ++) {
    
    
		a[0] ++;
		for (int i = 0; a[i]; i ++) {
    
    
			while (a[i] > 26) {
    
    
				a[i] -= 26;
				a[i + 1] ++;
			}
		}
		cout << i << "  -->  ";
		output();
	}
	cout << endl;
	return 0;
}

Question C

【Problem Description】

For a date, we can calculate the sum of the digits of the year, or the sum of the digits of the month and day. How many days are there in total from January 1, 1900 to December 31, 9999? The sum of the digits of the year is equal to the sum of the digits of the month plus the sum of the digits of the day.
 For example, November 13, 2022 satisfies the requirement because 2+0+2+2=(1+1)+(1+3).
 Please submit the total number of dates that meet the criteria.

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.

Solution: date simulation

// 答案:70910
#include <bits/stdc++.h>
using namespace std;

int sum_num(int x) {
    
    
	int sum = 0;
	while (x) {
    
    
		sum += (x % 10);
		x /= 10;
	}
	return sum;
}

bool check(int y) {
    
    
	return y % 4 == 0 && y % 100 != 0 || y % 400 == 0;
}

int days[13] = {
    
    0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int yy = 1900, MM = 1, dd = 1;

int main() {
    
    
	int ans= 0;
	while (yy < 10000) {
    
    
		int a = sum_num(yy);
		int b = sum_num(MM) + sum_num(dd);
		if (a == b) {
    
    
			ans ++; 
		}
		bool flag = (MM == 2 && check(yy));
		if (flag) days[2] ++;
		
		dd ++;
		if (dd > days[MM]) {
    
    
			dd = 1;
			MM ++;
			if (MM > 12) {
    
    
				MM = 1;
				yy ++;
			}
		}
		if (flag) days[2] --;
	}
	cout << ans << endl;
	return 0;
}

Question D

【Problem Description】

Xiaolan has 30 numbers, namely: 99, 22, 51, 63, 72, 61, 20, 88, 40, 21, 63, 30, 11, 18, 99, 12, 93, 16, 7, 53, 64, 9, 28, 84, 34, 96, 52, 82, 51, 77.
 Xiaolan can take two numbers with different serial numbers from these numbers, and there are 30*29/2=435 ways to take them.
 May I ask how many of these 435 methods yield the product of two numbers greater than or equal to 2022.

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.

Problem Solution: Cycle of Violence

// 答案:189
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;

int a[30];

int main() {
    
    
	for (int i = 0; i < 30; i ++) {
    
    
		cin >> a[i];
		getchar();
	}
	
	for (int i = 0; i < 30; i ++) {
    
    
		cout << a[i] << " ";
	}
	cout << "\n";
	
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < 30; i ++) {
    
    
		for (int j = i + 1; j < 30; j ++) {
    
    
			if (a[i] * a[j] >= 2022) {
    
    
				cout << a[i] << " * " << a[j] << " = " << a[i] * a[j] << "\n";
				ans ++;
			}
			cnt ++;
		}
	}
	cout << "cnt = " << cnt << endl;
	cout << ans << endl;
	return 0;
}

Question E

【Problem Description】

Xiaolan has a matrix of numbers with 30 rows and 60 columns, and each number in the matrix is ​​0 or 1.

110010000011111110101001001001101010111011011011101001111110
010000000001010001101100000010010110001111100010101100011110
001011101000100011111111111010000010010101010111001000010100
101100001101011101101011011001000110111111010000000110110000
010101100100010000111000100111100110001110111101010011001011
010011011010011110111101111001001001010111110001101000100011
101001011000110100001101011000000110110110100100110111101011
101111000000101000111001100010110000100110001001000101011001
001110111010001011110000001111100001010101001110011010101110
001010101000110001011111001010111111100110000011011111101010
011111100011001110100101001011110011000101011000100111001011
011010001101011110011011111010111110010100101000110111010110
001110000111100100101110001011101010001100010111110111011011
111100001000001100010110101100111001001111100100110000001101
001110010000000111011110000011000010101000111000000110101101
100100011101011111001101001010011111110010111101000010000111
110010100110101100001101111101010011000110101100000110001010
110101101100001110000100010001001010100010110100100001000011
100100000100001101010101001101000101101000000101111110001010
101101011010101000111110110000110100000010011111111100110010
101111000100000100011000010001011111001010010001010110001010
001010001110101010000100010011101001010101101101010111100101
001111110000101100010111111100000100101010000001011101100001
101011110010000010010110000100001010011111100011011000110010
011110010100011101100101111101000001011100001011010001110011
000101000101000010010010110111000010101111001101100110011100
100011100110011111000110011001111100001110110111001001000111
111011000110001000110111011001011110010010010110101000011111
011110011110110110011011001011010000100100101010110000010011
010011110011100101010101111010001001001111101111101110011101

Two locations are said to be connected if one can walk from one location marked 1 to another location marked 1 through up, down, left, and right. All locations connected to a location marked 1 (including itself) form a connected block.
 How big is the largest connected block in the matrix?

【Answer submission】

This is a question of filling in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer, only fill in this integer when submitting the answer, filling in redundant content will result in no scoring.

Solution: Guangsou

// 答案:148
#include <bits/stdc++.h>
using namespace std;

int m = 30, n = 60;
char mat[35][65];
int ans = 0;

int dx[4] = {
    
    1, 0, -1, 0};
int dy[4] = {
    
    0, 1, 0, -1};

int get_cnt(int i, int j) {
    
    
	queue<int> q;
	q.push(i * 100 + j);
	mat[i][j] = '0';
	int cnt = 0;
	while (q.size()) {
    
    
		int x = q.front();
		q.pop();
		i = x / 100;
		j = x % 100;
		cnt ++;
		
		for (int k = 0; k < 4; k ++) {
    
    
			int x = i + dx[k];
			int y = j + dy[k];
			if (x < 0 || x >= m || y < 0 || y >= n || mat[x][y] != '1') {
    
    
				continue;
			}
			mat[x][y] = '0';
			q.push(x * 100 + y);
		}
	}
	return cnt;
}

int main() {
    
    
	for (int i = 0; i < m; i ++) {
    
    
		cin >> mat[i];
	}
	for (int i = 0; i < m; i ++) {
    
    
		for (int j = 0; j < n; j ++) {
    
    
			if (mat[i][j] == '1') {
    
    
				ans = max(ans, get_cnt(i, j));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Question F

【Problem Description】

Given which day of the week a day is, what day of the week will it be after n days?

【Input format】

The first line of input contains an integer w, indicating which day of the week the given day is, w is 1 to 6 for Monday to Saturday, and w is 7 for Sunday.
 The second line contains an integer n.

【Output format】

One line of output contains an integer indicating which day of the week is n days later, 1 to 6 represent Monday to Saturday, and 7 represents Sunday.

【Sample input】

6
10

【Sample output】

2

[Evaluation use case scale and agreement]

1 <= n <= 1000000 for all evaluation cases.

Problem solution: take the remainder

#include <bits/stdc++.h>
using namespace std;

int w, n;

int main() {
    
    
	cin >> w >> n;
	w = (w + n) % 7;
	if (w == 0) w = 7;
	cout << w << endl;
	return 0;
}

Question G

【Problem Description】

Xiaolan is responsible for the installation of signal towers in an area. The entire area is a rectangular area. After the coordinate axes are established, the coordinates of the southwest corner are (0, 0), the coordinates of the southeast corner are (W, 0), and the coordinates of the northwest corner are (0, H), and the coordinates of the northeast corner are (W, H). Where W, H are integers.
 He set up signal towers at n positions, and each signal tower can cover a circle with a radius of R (including the edge) centered on itself.
 In order to check the signal coverage, Xiaolan plans to test all the points in the area where the horizontal and vertical coordinates are integers to check the signal status. The abscissa ranges from 0 to W, the ordinate ranges from 0 to H, and a total of (W+1) * (H+1) points are tested.
 Given the location of the signal tower, how many of these (W+1)*(H+1) points are covered by the signal.

【Input format】

The first line of input contains four integers W, H, n, R, separated by a space between adjacent integers.
 Next n lines, each line contains two integers x, y, representing the coordinates of a signal tower. Signal towers may overlap, indicating that two signal transmitters are installed in the same location.

【Output format】

The output line contains an integer representing the answer.

【Sample input】

10 10 2 5
 0 0
 7 0

【Sample output】

57

[Evaluation use case scale and agreement]

For all evaluation cases, 1 <= W, H <= 100, 1 <= n <= 100, 1 <= R <= 100, 0 <= x <= W, 0 <= y <= H.

Problem Solution: Violent Simulation

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 105;

int mat[N][N];
int w, h, n, r;
int a[N][2];

signed main() {
    
    
	
	cin >> w >> h >> n >> r;
	for (int i = 0; i < n; i ++) {
    
    
	    cin >> a[i][0] >> a[i][1];
	}
	int rr = r * r;
	int ans = 0;
	for (int i = 0; i <= w; i ++) {
    
    
	    for (int j = 0; j <= h; j ++) {
    
    
	        for (int k = 0; k < n; k ++) {
    
    
	            int x = (i - a[k][0]) * (i - a[k][0]) + (j - a[k][1]) * (j - a[k][1]);
	            if (x <= rr) {
    
    
	                ans ++;
	                break;
	            }
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}

Question H

【Problem Description】

Xiaolan has a rectangular water area of ​​n * m size, Xiaolan divides this water area into n rows and m columns, the number of rows is from 1 to n, and the number of columns is from 1 to m. The width of each row and each column is unit 1.
 Now, this water area is full of aquatic plants, and Xiaolan wants to clean up the aquatic plants.
 Each time, Xiaolan can clean up a rectangular area, from column c1 (inclusive) to column c2 (inclusive) of row r1 (inclusive) to row r2 (inclusive).
 After a period of cleaning, ask how many places have not been cleaned.

【Input format】

The first line of input contains two integers n, m separated by a space.
 The second line contains an integer t representing the number of cleanups.
 In the next t lines, each line has four integers r1, c1, r2, c2. Adjacent integers are separated by a space, indicating a cleanup. Note the order of entries.

【Output format】

The output line contains an integer representing the area that has not been cleaned.

【Sample input】

2 3
2
1 1 1 3
1 2 2 2

【Sample output】

2

【Sample input】

30 20
2
5 5 10 15
6 7 15 9

【Sample output】

519

[Evaluation use case scale and agreement]

For all evaluation cases, 1 <= r1 <= r2 <= n <= 100, 1 <= c1 <= c2 <= m <= 100, 0 <= t <= 100.

Problem Solution: Cycle of Violence

#include <bits/stdc++.h>
using namespace std;

const int N = 105;

int a[N][N];
int m, n;
int t;
int r1, c1, r2, c2;

int main() {
    
    
    cin >> m >> n;
    cin >> t;
    while (t --) {
    
    
        cin >> r1 >> c1 >> r2 >> c2;
        for (int i = r1; i <= r2; i ++) {
    
    
            for (int j = c1; j <= c2; j ++) {
    
    
                a[i][j] = 1;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; i ++) {
    
    
        for (int j = 1; j <= n; j ++) {
    
    
            ans += (a[i][j] == 0);
        }
    }
    cout << ans << endl;
    return 0;
}

Question I

【Problem Description】

Xiaolan is going to slide in an open field. The height of the field is different. Xiaolan uses a matrix of n rows and m columns to represent the field, and the values ​​in the matrix represent the height of the field.
 If Xiaolan is at a certain position, and the height of one of his up, down, left, and right positions is (strictly) lower than the current height, Xiaolan can slide there, and the sliding distance is 1.
 If Xiaolan is at a certain position, and the heights of all his up, down, left, and right positions are greater than or equal to the current height, Xiaolan's skating is over.
 Xiaolan cannot slide out of the field represented by the matrix.
 Xiaolan can choose any position to start gliding. May I ask how far Xiaolan can slide at most.

【Input format】

The first line of input contains two integers n, m separated by a space.
 The next n lines, each line contains m integers, separated by a space between adjacent integers, indicating the height of each position in turn.

【Output format】

The output line contains an integer representing the answer.

【Sample input】

4 5
1 4 6 3 1
11 8 7 3 1
9 4 5 2 1
1 3 2 2 1

【Sample output】

7

【Example description】

The sliding position is (2, 1), (2, 2), (2, 3), (3, 3), (3, 2), (4, 2), (4, 3) at a time.

[Evaluation use case scale and agreement]

For 30% of the evaluation cases, 1 <= n <= 20, 1 <= m <= 20, 0 <= height <= 100.
 For all evaluation cases, 1 <= n <= 100, 1 <= m <= 100, 0 <= height <= 10000.

Solution: memory search

#include <bits/stdc++.h>
using namespace std;

const int N = 105;

int a[N][N];
int mp[N][N];
int m, n;

int dx[4] = {
    
    1, 0, -1, 0};
int dy[4] = {
    
    0, -1, 0, 1};

int dfs(int i, int j) {
    
    
    if (mp[i][j] != -1) return mp[i][j];
    int ret = 0;
    for (int k = 0; k < 4; k ++) {
    
    
        int x = i + dx[k];
        int y = j + dy[k];
        if (x < 0 || x >= m || y < 0 || y >= n || a[x][y] >= a[i][j]) {
    
    
            continue;
        }
        ret = max(ret, dfs(x, y) + 1);
    }
    return mp[i][j] = ret;
}


int main() {
    
    
    memset(mp, -1, sizeof(mp));
    cin >> m >> n;
    for (int i = 0; i < m; i ++) {
    
    
        for (int j = 0; j < n; j ++) {
    
    
            cin >> a[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < m; i ++) {
    
    
        for (int j = 0; j < n; j ++) {
    
    
            ans = max(ans, dfs(i, j));
        }
    }
    cout << ans + 1 << endl;
    return 0;
}

Question J

【Problem Description】

Xiaolan has a sequence a[1], a[2], ..., a[n].
Given a positive integer k, for each serial number i between 1 and n, what is the number of a[ik], a[i-k+1], …, a[i+k] among the 2k+1 numbers What is the minimum value? When a subscript exceeds the range from 1 to n, the number does not exist, and only those values ​​that exist are used when calculating the minimum value.

【Input format】

The first line of input contains an integer n.
 The second line contains n integers representing a[1], a[2], …, a[n] respectively.
 The third line contains an integer k.

【Output format】

Output one line, containing n integers, representing the minimum value obtained for each sequence number respectively.

【Sample input】

5
5 2 7 4 3
1

【Sample output】

2 2 2 3 3

[Evaluation use case scale and agreement]

For 30% of the evaluation cases, 1 <= n <= 1000, 1 <= a[i] <= 1000.
 For 50% of the evaluation cases, 1 <= n <= 10000, 1 <= a[i] <= 10000.
 For all evaluation cases, 1 <= n <= 1000000, 1 <= a[i] <= 1000000.

Solution: monotonic queue

If you are familiar with STL, you can use map to record the number of occurrences of each number, control addition and deletion, and keep the first key in the map as the answer to be output

#include <bits/stdc++.h>
using namespace std;

const int N = 1E6 + 5;

int a[N];
int x;
int n, k;

int main() {
    
    
    deque<int> dq;
    
    cin >> n;
    for (int i = 1; i <= n; i ++) {
    
    
        cin >> a[i];
    }
    cin >> k;
    
    for (int i = 1; i <= n + k; i ++) {
    
    
        if (i <= n) {
    
    	// 右端点在数轴上
            x = a[i];
            while (dq.size() && dq.back() > x) {
    
    
                dq.pop_back();
            }
            dq.push_back(x);
        }
        if (i - k - k > 1) {
    
    	// 左端点超过 1
            x = a[i - k - k - 1];
            if (dq.front() == x) {
    
    
                dq.pop_front();
            }
        }
        if (i - k > 0) {
    
    	// 中点在数轴上
            cout << dq.front();
            if (i != n + k) cout << " ";
        }
    }
    cout << endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/Cey_Tao/article/details/129470771