2022 The 13th Lanqiao Cup Provincial Competition C/C++ Group B Test Questions and Individual Solution

2022 The 13th Lanqiao Cup Provincial Competition C/C++ Group B Test Questions and Individual Solution

Question A: Convert decimal to decimal

Total score for this question: 5 points

【Problem Description】

How much is a positive integer in decimal (2022) converted into decimal?

【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

2 * 9^0 + 2 * 9^1 + 0 + 2 * 9^3 = 1478

Question B: Shun Zi Dates

Total score for this question: 5 points

【Problem Description】

Xiao Ming especially likes Shunzi. Shunzi refers to three consecutive numbers: 123, 456, etc. A sequence date refers to a date in which any consecutive three-digit number is a sequence in the yyyymmdd notation of the date. For example, 20220123 is a straight date because it has a straight: 123; and 20221023 is not a straight date, it has no straight. Xiao Ming wants to know how many straight dates there are in the entire 2022 year.

【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: Calendar

Many people are discussing whether 012 is a straight, because the title says that the straight in 0123 is 123, I forget it, if not, the answer should be 4

年份 2022 是不变的,而且不可能搭上顺子,所以只考虑后四位即可
可能搭上顺子的月份有:
    1月:0120 ~ 012910 个,顺子是 012 (其中 0123 可以认为顺子是 123)
    10月:1012,顺子是 012
    11月:1123,顺子是 123
    12月:12301231,顺子是 123
一共 14

There is a set of ambiguity in the meaning of the title of the Blue Bridge Cup

Test Question C: Brushing Question Statistics

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 10 points

【Problem Description】

Xiao Ming decided to work hard to prepare for the Blue Bridge Cup competition from next Monday . He plans to do α questions every day from Monday to Friday, and b questions every day on Saturday and Sunday. Please help Xiaoming calculate, according to the plan, how many days will he realize that the number of questions is greater than or equal to n?

【Input format】

Input a line containing three integers a, b and n.

【Output format】

Output an integer representing the number of days.

【Sample input】

10 20 99

【Sample output】

8

[Evaluation use case scale and agreement]

For 50% of the evaluation cases, 1 ≤ a, b, n ≤ 10^5.

For 100% of the evaluation cases, 1≤ a, b, n ≤ 10^15.

Problem solution: take the remainder

Looking at the data scale of 1E15, if the violent simulation is stable, it will time out

You can first calculate how many questions you can do every week, and then use division and taking the remainder to control the amount of questions you can do within a week after taking the remainder, and then judge whether you can finish the five days in a week, it is relatively simple

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

ll a, b, n, k;
ll ans = 0;

int main() {
    
    
	cin >> a >> b >> n;
	k = a * 5 + b + b;
	ans += n / k * 7;
	n %= k;
	if (n <= a * 5) {
    
    
		ans += n / a + (n % a != 0);
	}
	else {
    
    
		n -= a * 5;
		ans += 6 + (n > b);
	}
	cout << ans << endl;
	return 0;
}

After doing so many questions, Xiao Ming is so good...

Test Question D: Pruning Shrubs

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 10 points

【Problem Description】

Alice has a bush trimming job to do.

There are N shrubs neatly arranged in a row from left to right. Alice will prune a shrub every evening so that the height of the shrub becomes 0 cm. The order in which Alice prunes the shrubs starts from the leftmost shrub, and prunes one shrub to the right every day. When the rightmost shrub is pruned, she turns around and starts pruning the shrub to the left the next day. Turn around again until the leftmost shrub has been pruned. And so on and on .

The shrub will grow 1 cm taller every day from morning to evening , and not grow taller the rest of the time. In the morning of the first day, the height of all bushes was 0 cm. Alice wants to know the maximum height of each bush.

【Input format】

A positive integer N, meaning as described in the title.

【Output format】

Output N lines, each with an integer, and the i-th line indicates how high the i-th tree can grow from left to right.

【Sample input】

3

【Sample output】

4
2
4

[Evaluation use case scale and agreement]

For 30% of the data, N ≤ 10.
For 100% of the data, 1< N ≤ 10000.

Solution: Greedy

Note that each shrub will first grow 1 cm taller on the day it is pruned before being pruned

For each shrub, there are two possibilities for the time period when it grows to the highest: after being cut, it is cut to the right and then turned back, and after being cut, it is cut to the left and then turned back

Assuming that there are x shrubs on the left side of a shrub and y shrubs on the right side, it is easy to find that the maximum height of this shrub is max(x, y) * 2, and each shrub on its left (right) side is cut before it will grow 1 cm tall, including before it is cut

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

int n;

int main() {
    
    
	cin >> n;
	for (int i = 0; i < n; i++) {
    
    
		int x = max(i, n - i - 1);
		cout << x * 2 << endl;
	}
	return 0;
}

Alice's house is pretty big for so many shrubs!

Test question E: Subtraction in base X

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points

【Problem Description】

The hexadecimal system specifies how many digits the number is in.

The base X is a very magical base, because the base of each digit is not fixed! For example, for some base X, the lowest digit is binary, the second digit is decimal, and the third digit is octal. Then the X base number 321 is converted to the decimal number 65.

Now there are two integers A and B expressed in base X, but the exact base of each digit is not sure yet. We only know that A and B have the same base rule, and the highest number of each number is N base, and the lowest is binary. Please calculate the minimum possible result of AB.

Please note that you need to ensure that both A and B are legal in the base X, that is, the number of each digit is smaller than its base.

【Input format】

The first line is a positive integer N, the meaning is as described in the title.
The second line is a positive integer Ma, indicating the number of digits of the X-ary number A.
In the third line, Ma are integers separated by spaces, which represent the decimal representation of the digits of the X-base number A in order from high to low.
The fourth line is a positive integer M, indicating the number of digits of the X-ary number B.
The fifth line contains Mb integers separated by spaces, representing the decimal representation of the digits of the X-base number B in order from high to low.
Note that all numbers in the input are in decimal.

【Output format】

Output an integer per line, representing the result of modulo 1000000007 after converting the smallest possible value of the result of the X-ary number A - B to decimal.

【Sample input】

11
3
10 4 0
3
1 2 0

【Sample output】

94

【Example description】

When the base system is: binary at the lowest digit, base 5 at the second digit, and base 11 at the third digit, the difference obtained by subtraction is the smallest. At this time, A is 108 in decimal system, B is 14 in decimal system, and the difference is 94.

[Evaluation use case scale and agreement]

For 30% of the data, N≤ 10; Ma, Mb ≤ 8.
For 100% of the data, 2 < N ≤ 1000; 1 ≤ Ma, Mb, ≤ 100000; A ≥ B .

Solution: Greedy

I wanted to do a deep search, but if I look at the data range, I’ll forget it

Assuming that A and B are both three-digit numbers, they are a2a1a0 and b2b1b0 respectively.
The base number (pi) of each bit is p2p1p0 respectively

Then we can know that the decimal system of A should be: a0 * 1 + a1* p0 + a2 * (p0 * p1), and B is: b0 * 1 + b1* p0 + b2 * (p0 * p1)

Then there is A - B = (a0 - b0) + (a1 - b1) * p0 + (a2 - b2) * (p0 * p1)

If you look at it this way, each digit (pi) should be in the smallest possible base (the smallest is binary)

At this point, I have a guess, should I raise the base number when (ai - bi) is negative?

Note that A >= B in the title, if there is ai < bi, then there must be aj > bj in the higher position

Take the above A - B formula to illustrate, assuming (a1 - b1) is less than 0, so make p0 larger, so as to make the result smaller

But when p0 becomes larger, the result of (a2 - b2) * (p0 * p1 ) must also become larger, and the result is smaller than (a1 - b1) * p0, because it also multiplies p1, and As the base number of a1 and b1, p1 must be greater than a1 and b1, and must be greater than (b1 - a1)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAXM = 100005;

int n, ma, mb;
int a[MAXM], b[MAXM];
ll ans = 0, bac = 1;

int main() {
    
    
	cin >> n;
	cin >> ma;
	for (int i = 1; i <= ma; i++) {
    
    
		cin >> a[i];
	}
	cin >> mb;
	for (int i = 1; i <= mb; i++) {
    
    
		cin >> b[i];
	}
	int i = ma, j = mb;
	while (i > 0) {
    
    
		ans += (a[i] - b[j]) * bac;
		ans %= MOD;
		ll p = max(a[i], b[j]) + 1;
		bac *= max(p, 2LL);
		bac %= MOD;
		i--;
		if (j) j--;
	}
	cout << ans << endl;
	return 0;
}

To be honest, I don’t know if this is right or not. I often have a hazy feeling when doing blue bridge questions, and I don’t know if the idea is feasible or not.

Question F: Statistics Submatrix

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 15 points

【Problem Description】

Given an N×M matrix A, please count how many sub-matrices (minimum 1×1, maximum NxM) satisfy the sum of all numbers in the sub-matrix not exceeding the given integer K?

【Input format】

The first row contains three integers N, M and K.
The next N rows contain M integers each, representing the matrix A.

【Output format】

An integer representing the answer.

【Sample input】

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

【Sample output】

19

【Example description】

There are a total of 19 sub-matrices that meet the conditions, including:

There are 10 of size 1×1.
There are 3 of the size 1×2.
There are 2 of the size 1×3.
There is 1 of size 1×4.
There are 3 of the size 2×1.

[Evaluation use case scale and agreement]

For 30% of the data, N, M ≤ 20.

For 70% of the data, N, M ≤ 100.

For 100% of the data, 1 ≤ N,M ≤ 500; 0 ≤ Aij ≤1000; 1 ≤ K ≤ 250000000.

Problem solution: two-dimensional prefix sum + dichotomy

When I saw the question, I thought of the prefix sum, but the violent enumeration must have timed out. I thought of a crooked idea of ​​​​half enumeration + binary search. The time complexity is about O(n^3 * log(n)), probably 10^9, plus a little pruning, can you see luck

Assuming (i, j) is the starting point coordinates of the sub-matrix, (x, y) is the end point coordinates, enumerate i, j, x, binary search for the maximum y that meets the conditions, is to find the starting point is (i, j), and the end point is at How many matrices can there be at most in row x

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 505;

ll m, n, k;
ll a[N][N];
ll ans = 0;

ll getsum(int i, int j, int x, int y) {
    
    
	return a[x][y] - a[i - 1][y] - a[x][j - 1] + a[i - 1][j - 1];
}

int main() {
    
    
	cin >> m >> n >> k;
	for (int i = 1; i <= m; i++) {
    
    
		for (int j = 1; j <= n; j++) {
    
    
			cin >> a[i][j];
			a[i][j] += a[i - 1][j] - a[i - 1][j - 1] + a[i][j - 1];
		}
	}
	for (int i = 1; i <= m; i++) {
    
    
		for (int j = 1; j <= n; j++) {
    
    
			if (getsum(i, j, i, j) > k) continue;
			for (int x = i; x <= m; x++) {
    
    
				int l = j, r = n;
				while (l < r) {
    
    
					int mid = (l + r + 1) >> 1;
					if (getsum(i, j, x, mid) > k) r = mid - 1;
					else l = mid;
				}
				if (getsum(i, j, x, l) > k) break;
				ans += l - j + 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

True solution: prefix sum + number of consecutive subsections

There is a solution to this problem. It is actually a routine problem.
First determine the two column boundaries of the sub-matrix, and then do a row traversal, which is to find the number of consecutive sub-segments that meet the conditions (double-pointer sliding window), and the complexity is reduced to O(n ^3)
Since you only need to get the sum in a certain row each time, you only need to do the one-dimensional prefix sum

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 505;

ll m, n, k;
ll a[N][N];
ll ans = 0;

int main() {
    
    
	cin >> m >> n >> k;
	for (int i = 1; i <= m; i++) {
    
    
		for (int j = 1; j <= n; j++) {
    
    
			cin >> a[i][j];
			a[i][j] += a[i][j - 1];
		}
	}
	for (int i = 1; i <= n; i++) {
    
    
		for (int j = i; j <= n; j++) {
    
    
			int left = 1;
			ll cur = 0;
			for (int right = 1; right <= m; right++) {
    
    
				cur += a[right][j] - a[right][i - 1];
				while (cur > k) {
    
    
					cur -= a[left][j] - a[left][i - 1];
					left++;
				}
				ans += right - left + 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Test Question G: Block Drawing

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 20 points

【Problem Description】

Xiao Ming has recently become obsessed with building block painting. There are two types of building blocks, namely Type I (size 2 unit area) and L type (size 3 unit area):

insert image description here

At the same time, Xiao Ming has a canvas with an area of ​​2×N, and the canvas is composed of 2×N 1×1 areas. Xiao Ming needs to use the above two building blocks to fill the canvas. He wants to know how many different ways there are in total? The building blocks can be rotated arbitrarily, and the direction of the canvas is fixed.

【Input format】

Enter an integer N, representing the canvas size.

【Output format】

Output an integer representing the answer. Since the answer may be very large, output its value modulo 1000000007

【Sample input】

3

【Sample output】

5

【Example description】

The five situations are shown in the figure below, and the colors are just to identify different building blocks;

insert image description here

[Evaluation use case scale and agreement]

1 ≤ N ≤ 10000000 for all test cases.

Problem solution: dynamic programming (wrong solution)

To make n columns of squares, you can add a vertical I-shaped building block after n - 1 squares, or add two horizontal I-shaped blocks after n - 2 squares, or you can add n - 3 squares Two swinging methods of adding two L-shaped building blocks on the column grid

Use dp[i] to represent the arrangement of i-column squares

Then, when i >= 3, dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3] * 2;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 10000005;

int n;
ll dp[N];

int main() {
    
    
	cin >> n;
	dp[0] = dp[1] = 1;
	dp[2] = 2;
	for (int i = 3; i <= n; i++) {
    
    
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3] * 2;
		dp[i] %= MOD;
	}
	cout << dp[n] << endl;
	return 0;
}

The idea is too simple, send it!

Problem Solution: Dynamic Programming

I read what others said, you can put an L-shaped block first, then put several horizontal I-shaped blocks in a row, and then put an L-shaped block at the end, and hit the forehead directly with a heavy hammer. However, there is another situation
insert image description here
:

insert image description here

In other words, is it not good for Lanqiao to only put a small sample on purpose (although it is really a test of thinking)

Then, on the basis of the above misunderstanding, to lay out n columns of squares, it can also be converted from (n - 4, n - 5, n - 6, n - 7, ...)

也就有:
① dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3] * 2 + dp[i - 4] * 2+ dp[i - 5] * 2 + …… + * dp[1] * 2
② dp[i - 1] = dp[i - 2] + dp[i - 3] + dp[i - 4] * 2 + dp[i - 4] * 2+ dp[i - 5] * 2 + …… + * dp[1] * 2

① - ② 得出 dp[i] - dp[i - 1] = dp[i - 1] + dp[i - 3] 即 dp[i] = dp[i - 1] * 2 + dp[i - 3]

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 10000005;

int n;
ll dp[N];

int main() {
    
    
	cin >> n;
	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 5;
	for (int i = 4; i <= n; i++) {
    
    
		dp[i] = (dp[i - 1] * 2 + dp[i - 3]) % MOD;
	}
	cout << dp[n] << endl;
	return 0;
}

Question H: Minesweeper

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 20 points

【Problem Description】

Xiao Ming has recently become obsessed with a game called "Minesweeper". The task of one of the checkpoints is as follows. There are n bombs placed on a two-dimensional plane. The i-th bomb (xi, yi, ri) indicates that there is a bomb at the coordinates (xi, yi), and its explosion range is A circle with radius ri.
insert image description here
In order to pass through this land smoothly, players need to clear mines. The player can launch m mine-clearing rockets. Xiaoming has planned the launch direction of each mine-clearing rocket. The jth mine-clearing rocket (xj, yj, rj) means that the mine-clearing rocket will explode at (xj, yj). Its The explosion range is a circle with radius rj, and the mines within the explosion range will be detonated. At the same time, when the mine is detonated, the mines within its explosion range will also be detonated. Now Xiao Ming wants to know how many bombs he detonated this time?

You can think of both mine blasting and demining rockets as a point on a plane. Multiple mine-exploding and mine-clearing rockets can exist at a single point . It will also be detonated when the mine is on the boundary of the explosion range.

【Input format】

The first line of input contains two integers n, m.
The next n lines, each line contains three integers xi, yi, ri, indicating a mine bombing information.
In the next m lines, each line contains three integers xj, yj, rj, representing the information of a demining rocket.
[Output Format]
Output an integer to represent the answer.

【Sample input】

2 1
2 2 4
4 4 2
0 0 5

【Sample output】

2

【Example description】

The example picture is as follows, mine removal rocket 1 covers mine bomb 1, so bomb bomb 1 is excluded; bomb bomb 1 covers bomb bomb 2, so bomb bomb 2 is also excluded.

[Evaluation use case scale and agreement]

For 40% of the evaluation cases: 0 ≤ x, y ≤ 10^9, 0 ≤ n, m ≤ 10^3, 1 < r ≤ 10. For 100% of the evaluation cases: 0 ≤ x, y ≤ 10^9
, 0 ≤ n, m ≤ 5 × 10^4, 1 ≤ r ≤ 10.

Solution: Guangsou

During the competition, I didn’t see the question saying that one point can have multiple mines, so I sent it again!

The range of coordinates 10^9 is too big, so I use a hash table to put pairs. Multiple mines on the same point can be compressed in state. Use hundreds to start the number of mines, and singles to put the maximum radius.

Put the mines that are about to explode in the queue, and gather the mines that have been scanned

It's more violent, I don't know if it will work

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

struct point {
    
    
	int x, y, r;
	point(int xx, int yy, int rr) : x(xx), y(yy), r(rr) {
    
    }
};
double get_len(int i, int j, int  x, int y) {
    
    
	return sqrt((i - x) * (i - x) + (j - y) * (j - y));
}

map<pair<int, int>, int> mp;
queue<point> q;
set<pair<int, int> > s;

int m, n;
ll ans = 0;

int main() {
    
    
	cin >> n >> m;
	int x, y, r;
	for (int i = 0; i < n; i++) {
    
    
		cin >> x >> y >> r;
		int tmp = mp[make_pair(x, y)] + 100;
		mp[make_pair(x, y)] = max(tmp, tmp / 100 * 100 + r);
	}
	for (int i = 0; i < m; i++) {
    
    
		cin >> x >> y >> r;
		q.push(point(x, y, r));
	}
	
	while (!q.empty()) {
    
    
		point po = q.front();
		x = po.x, y = po.y, r = po.r;
		q.pop();
		for (int i = x - r; i <= x + r; i++) {
    
    
			for (int j = y - r; j <= y + r; j++) {
    
    
				pair<int, int> pir(i, j);
				if (s.count(pir)) continue;
				if (!mp.count(pir)) continue;
				if (get_len(i, j, x, y) > r) continue;
				s.insert(pir);
				q.push(point(i, j, mp[pir] % 100));
				ans += mp[pir] / 100;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Test Question: Li Bai Dajiu Enhanced Edition

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 25 points

【Problem Description】

It is said that Li Bai, a great poet, enjoyed drinking all his life. Luckily he never drives.

One day, he came out of the house with a flagon, and there were 2 buckets of wine in the flagon. As he walked he sang:

Walking on the street with nothing to do, carrying a pot to get wine.
Every store doubles, and every flower drinks a bucket.

Along the way, he encountered shops N times and flowers M times. It is known that Hua was the last person he met , and he just finished drinking.

Please calculate the order in which Li Bai encountered shops and flowers along the way. How many different possibilities are there?

Note: It is legal to meet the store when there is no wine in the jug (0 Dou), and there is still no wine after doubling, but it is illegal to meet flowers when there is no wine .

【Input format】

The first line contains two integers N and M.

【Output format】

Output an integer representing the answer. Since the answer may be large, the result modulo 1000000007 is output.

【Sample input】

5 10

【Sample output】

14

【Example description】

If we use 0 to represent flowers and 1 to represent stores, the order of the 14 types is as follows:

010101101000000
010110010010000
011000110010000
100010110010000
011001000110000
100011000110000
100100010110000
010110100000100
011001001000100
100011001000100
100100011000100
011010000010100
100100100010100
101000001010100

[Evaluation use case scale and agreement]

For 40% of evaluation cases: 1 ≤ N, M ≤ 10.
For 100% of evaluation cases: 1 ≤ N, M ≤ 100.

Problem solution: memory search + pruning

It is easier to think of deep search, add the results of order n - 1 and order m - 1, on this basis there are several rules for pruning

Use k to represent the amount of wine:
if k == 0, there must be m == n == 0, the result is 1, otherwise there is no solution, because the last encounter must be a flower, and it is impossible to meet a flower when there is no wine Legal
If k > m, there must be no solution
If k != 0 and n >= m, there must be no solution
If n == 0, there must be k == m, the result is 1, otherwise there is no solution

Because the maximum value of n and m is 100, the value of k will not be greater than m after pruning, so a three-dimensional array can be used for memorization
(however, the hash table I used in the game, and it seems that the judgment of n == 0 is missing condition……)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 105;

ll mp[N][N][N];

ll dfs(int n, int m, int k) {
    
    
	if (k == 0) return (m == 0 && n == 0);
	if (k > m || n >= m) return 0;
	if (n == 0) return k == m;
	if (mp[n][m][k] != -1) return mp[n][m][k];
	ll ans = dfs(n, m - 1, k - 1) + dfs(n - 1, m, k + k);
	ans %= MOD;
	mp[n][m][k] = ans;
	return ans;
}

int main() {
    
    
	memset(mp, -1, sizeof mp);
	int m, n;
	cin >> n >> m;
	cout << dfs(n, m, 2) << endl;
	return 0;
}

It can also be dynamically programmed, but not written

Test Question J: Cutting Bamboo

Time limit: 1.0s Memory limit: 256.0MB Total score for this question: 25 points
[Problem description]

On this day, Xiao Ming was chopping bamboo, and there were n bamboos lined up in front of him. At the beginning, the height of the i-th bamboo was hi.

He felt that it was too slow to cut down one by one, so he decided to use magic to chop bamboo. Magic can be used on a continuous section of bamboo of the same height. Assuming that the height of this section of bamboo is H, then using magic once can change the height of this section of bamboo to [ sqrt( [H / 2] + 1 ) ], where [ x] means to round down x. Xiao Ming wants to know how many times he can use magic at least to make the height of all bamboos become 1.

【Input format】

The first line is a positive integer n, representing the number of bamboos.

The second line contains a positive integer h separated by n spaces, indicating the height of each bamboo.

【Output format】

An integer representing the answer.

【Sample input】

6
2 1 4 2 6 7

【Sample output】

5

[Example description]
One of the solutions: 2 1 4 2 6 7
→2 1 4 2 6 2
→2 1 4 2 2 2
→2 1 1 2 2 2
→1 1 1 2 2 2
→1 1 1 1 1 1

A total of 5 steps are required to complete

[Evaluation use case scale and agreement]

For 20% of the data, it is guaranteed that n ≤ 1000, hi ≤ 10^6.
For 100% of the data, it is guaranteed that n ≤ 2 × 10^5, hi ≤ 10^18.

Problem solution: Greedy defrauding points

As soon as I saw segmented modification, I thought of the line segment tree, but I still had no idea, and 10^18 is too big

Look at the example and guess a greedy one, find the maximum value and modify it every time, if it is the same in a row, modify it together

Then violently simulate, if you can fool two samples, it is considered a success

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200005;

int n;
ll a[N], ans = 0;

int main() {
    
    
	cin >> n;
	for (int i = 0; i < n; i++) {
    
    
		cin >> a[i];
	}
	while (true) {
    
    
		int idx = 0;
		for (int i = 0; i < n; i++) {
    
    
			if (a[i] > a[idx]) idx= i;
		}
		if (a[idx] == 1) break;
		ll val = a[idx];
		for (int i = idx; a[i] == val; i++) {
    
    
			a[i] = sqrt(a[i] / 2 + 1);
		}
		ans ++;
	}
	cout << ans << endl;
	return 0;
}

To sum it up: did you send it? sent again? The answer is to send!

The biggest change in this competition is that the fill-in-the-blank questions have become two questions, but the overall difficulty is not too high (only for C++ group B)
. Looking at so many programming questions is exhausting. There are eight big questions, and I don’t even want to read the questions later. I
hope that the questions from the Blue Bridge Cup will be optimized to make the meaning of the questions more accurate. It is best to simplify the
question B. Shunzi date gives me the feeling that I am playing a game, but let me guess what the rules of the game are, and I can only play it once

Guess you like

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