[Blue Bridge Cup Sprint] Blue Bridge Cup 12th Provincial Competition C++b Group Real Questions-Programming Questions

Table of contents

Question F: Time Display

problem solving ideas

the code

Test Question G: Weighing with Weights

problem solving ideas

the code

Question H: Yang Hui Triangle

problem solving ideas

the code

Question I: Bidirectional Sorting

problem solving ideas

Item J: Bracket Sequences

problem solving ideas


Question F: Time Display

【Problem Description】

Xiaolan wants to cooperate with a friend to develop a time display website.

On the server, the friend has obtained the current time, represented by an integer,

The value is the number of milliseconds that have elapsed since January 1, 1970 00:00:00 to the current moment.

Now, Xiaolan wants to display this time on the client.

Xiaolan does not need to display the year, month, and day, but only needs to display the hour, minute, and second, and does not need to display the millisecond, just discard it.

Given a time represented by an integer, please output the hours, minutes and seconds corresponding to this time.

【Input format】

Input a line containing an integer representing time.

【Output format】

Output the current time represented by hours, minutes and seconds, in the format of HH:MM:SS,

Where HH represents, the value is 0 to 23,

MM means points, the value is 0 to 59,

SS means seconds, the value is 0 to 59.

When the hours, minutes and seconds are less than two digits, the leading 0 is added.

【Test sample 1】

Input:
46800999

Output:
13:00:00

【Test sample 2】

Input:
1618708103123

Output:
01:08:23

[Evaluation use case scale and agreement]

For all evaluation cases, the given time is a positive integer not exceeding 10 to the power of 18.

problem solving ideas

This is a simple mock question,

According to the number of milliseconds given in the title, just find the current time.

the code

#include <iostream>
using namespace std;

int main() {
	long long t;
	cin >> t;
	int h = t / 1000 / 60 / 60 % 24;
	int m = t / 1000 / 60 % 60;
	int s = t / 1000 % 60;
	printf("%02d:%02d:%02d", h, m, s);
	return 0;
}

Test Question G: Weighing with Weights

【Problem Description】

You have a balance and N weights,

The weights of these N weights are W1 , W2 , ⋅ ⋅ ⋅ , WN in sequence.

Please calculate how many different weights you can weigh in total?

Note that weights can be placed on both sides of the balance.

【Input format】

You have a balance and N weights, and the weights of these N weights are W1 , W2 , ⋅ ⋅ ⋅ , WN in sequence.

【Output format】

Output an integer representing the answer.

【Test sample 1】

Input:
3
1 4 6

Output:
10

Explanation:
能称出的 10 种重量是:1、2、3、4、5、6、7、9、10、11。
1 = 1;
2 = 6 − 4 (天平一边放 6,另一边放 4);
3 = 4 − 1;
4 = 4;
5 = 6 − 1;
6 = 6;
7 = 1 + 6;
9 = 4 + 6 − 1;
10 = 4 + 6;
11 = 1 + 4 + 6。

[Evaluation use case scale and agreement]

1 ≤ N ≤ 15 for 50% of the evaluation cases.

For all evaluation cases, 1 ≤ N ≤ 100, the total weight of N weights shall not exceed 100000.

problem solving ideas

This is a dynamic programming problem.

But I don't know dynamic programming, so I can only write a violent search,

The following is the code: (only 50% use cases)

the code

#include <iostream>
using namespace std;

int n, res;
int w[10000];
bool st[10000];

void dfs(int x, int sum) {
	if (x == n) {
		//有重量且该重量没被标记过
		if (!st[sum] && sum > 0) {
			st[sum] = true;
			res++;
			return;
		}
	}
	else {
		dfs(x + 1, sum + w[x]);//放左边
		dfs(x + 1, sum);	   //不放
		dfs(x + 1, sum - w[x]);//放右边
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &w[i]);

	dfs(0, 0);

	printf("%d\n", res);
	return 0;
}

Question H: Yang Hui Triangle

【Problem Description】

The figure below is the famous Yang Fai triangle:

If we arrange all the numbers in a column from top to bottom and from left to right, we can get the following sequence:

If we arrange all the numbers in a column from top to bottom and from left to right, we can get the following sequence:

1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ...

Given a positive integer N, what number is the first occurrence of N in the output sequence?

【Input format】

Enter an integer N.

【Output format】

Output an integer representing the answer.

【Test sample 1】

Input:
6

Output:
13

[Evaluation use case scale and agreement]

1 ≤ N ≤ 10 for 20% of evaluation cases;

1 ≤ N ≤ 1e9 for all evaluation cases.

problem solving ideas

A rookie can't do it,

Only 1000 numbers can be violently enumerated to construct the Yanghui triangle.

(Only take about 40% of the score)

the code

#include <iostream>
using namespace std;

const int N = 1010;
int n = 1000;
int x;
int a[N][N];

int main() {
	scanf("%d", &x);
	a[1][1] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
		}
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			cnt++;
			if (a[i][j] == x) {
				cout << cnt << endl;
				return 0;
			}
		}
	}
	return 0;
}

Question I: Bidirectional Sorting

【Problem Description】

Given the sequence (a1, a2, ⋅⋅⋅, an) = (1, 2,⋅⋅⋅, n), ai = i .

Xiaolan will perform m operations on this sequence,

Each time it is possible to arrange a1 , a2 , ⋅⋅⋅ , aqi in descending order, or aqi, aqi + 1 in ascending order.

Request the sequence after the operation completes.

【Input format】

The first line of input contains two integers n, m, representing the length of the sequence and the number of operations, respectively.

The next m lines describe the operation on the sequence, where the i-th line contains two integers pi, qi represent the operation type and parameters.

When pi = 0, it means to arrange a1, a2, ⋅⋅⋅, aqi in descending order; when pi = 1, it means to arrange aqi, aqi + 1, ⋅⋅⋅, an in ascending order.

【Output format】

Output a line, containing n integers, separated by a space between adjacent integers, indicating the sequence after the operation is completed.

【Test sample 1】

Input:
3 3
0 3
1 2
0 2

Output:
3 1 2

[Evaluation use case scale and agreement]

For 30%30% of the evaluation cases, n,m≤1000;

For 60%60% of the evaluation cases, n,m≤5000;

For all evaluation cases, 1 ≤ n, m ≤ 1e5, 0 ≤ pi ≤ 1, 1 ≤ qi ≤ n1.

problem solving ideas

It is too difficult for me to write. . . .

Item J: Bracket Sequences

problem solving ideas

Don't look, I can't do this problem anymore. . . Woohoo. . .

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/129923584