Blue Bridge Cup Daily Question 2023.9.15

Lanqiao Cup 2022 Thirteenth Provincial Competition Real Questions-Pruning Shrubs-C Language Network (dotcpp.com)

Question description

Alice has a job to do, pruning shrubs. There are N shrubs arranged neatly in a row from left to right. Alice will prune a shrub every evening so that the height of the shrub becomes 0 cm. Alice prunes the shrubs in order, starting with the leftmost shrub and pruning one shrub to the right each day. After pruning the rightmost shrub, she would reverse direction and start pruning the shrubs to the left the next day. Turn around again after pruning the leftmost shrub. Then the cycle repeats. The shrub grows 1 centimeter each day from morning to evening and does not grow any other time. On the morning of the first day, the height of all shrubs is 0 cm. Alice wants to know how tall each bush can grow.

analyze

Just simulate

The height of growth is the time between pruning and the next pruning. It is divided into two parts. One part is walking from left to right and back from the right. This interval is 2 * (n - i), and the other part is Go from right to left, and then come back from the left. This interval is 2 * (i - 1)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cout << max((n - i), (i - 1)) * 2 << '\n';
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_75087931/article/details/132901422
Recommended