The 13th Blue Bridge Cup Provincial D: Building Shrubs (Thinking)

 Analysis: One thing we can obviously think of is that the height of the ith tree is the interval between the two times we build the ith tree, and this is obviously divided into two cases, one is to prune to the right to the nth After a tree, go back to the i-th tree, the interval corresponding to this case is 2*(ni), and another is to prune to the left to the first tree and then return to the i-th tree, which corresponds to The interval is 2*(i-1), taking a maximum of these two cases to get the answer .

Here is the code:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
using namespace std;
const int N=100030;
int a[N],b[N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		a[i]=(i-1)*2;
		b[i]=(n-i)*2;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",max(a[i],b[i]));
	return 0;
}

Guess you like

Origin blog.csdn.net/AC__dream/article/details/124066607