当前位置:网站首页>Question D: pruning shrubs
Question D: pruning shrubs
2022-07-25 03:09:00 【Leng Chi】
【 Problem description 】 Alice has to finish a job of pruning shrubs . Yes N The shrubs are arranged neatly from left to right . Alice trims a bush at the party every day wood , Make the height of the Bush 0 centimeter . Alice's order of pruning shrubs is to start with the shrub on the far left , Trim a shrub to the right every day . When the rightmost Bush is trimmed , She'll turn around , The next day Start trimming shrubs to the left . Until you trim the leftmost shrub and turn the direction again . And then go back and forth . Shrubs grow every day from morning to evening 1 centimeter , And the rest of the time will not grow tall . On the first day In the morning , The height of all shrubs is 0 centimeter . Alice wanted to know how high each Bush was at the top .
【 Input format 】 A positive integer N , The meaning is as stated in the title .
【 Output format 】 Output N That's ok , One integer per row , The second line indicates from left to right i How high can a tree grow .
【 The sample input 】 3
【 Sample output 】 4 2 4
【 Evaluate use case size and conventions 】 about 30% The data of ,N ≤ 10. about 100% The data of ,1 < N ≤ 10000.

Do you understand the image ? For the first time, we cut from the first Bush to the last Bush , When I came back, I started from n-1 Cut shrubs to the first shrub , And then from the 2 Cut shrubs to the last one to complete the cycle .
#include <iostream>
using namespace std;
long long data1[100000];
long long max1[100000];
long long n;
long long index1 = 1;
int main(int argc, char *argv[])
{
cin >> n;
for (int i = 1; i <= 2; i++)
{
if(i==2)
{
index1 = 2; // The first 2 The second cycle starts from 2 Start
}
while (index1 <= n)
{
for (int i = 1; i <= n; i++)
{
data1[i] = data1[i] + 1;
}
if (data1[index1] > max1[index1]) // If the height of the shrub you cut , Higher than the highest height of that Bush , Just update the maximum height .
{
max1[index1] = data1[index1];
}
data1[index1] = 0;
index1++;
}
if(i==2) // The first 2 Times from 2 To n, Don't come back later .
{
break;
}
// here index1 by n+1
index1 = index1 - 2; // The first cycle comes back from n-1 Start
while (index1 >= 1)
{
for (int i = 1; i <= n; i++)
{
data1[i] = data1[i] + 1;
}
if (data1[index1] > max1[index1])
{
max1[index1] = data1[index1];
}
data1[index1] = 0;
index1--;
}
}
for (int i = 1; i <= n; i++)
{
cout << max1[i] << endl;
}
return 0;
}边栏推荐
- Resolve the error: org.apache.ibatis.binding.bindingexception
- Ffmpeg 4.3 add custom demuxer
- Concurrent programming day01
- How to use two stacks to simulate the implementation of a queue
- Error: tomee required to support ear/ejb deployment
- Review all frames before sum of SSM frames
- Riotboard development board series notes (VIII) -- building desktop system
- JS interview question - what is the difference between Es5 and ES6?
- Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
- Read and upgrade st-link chip information and SWD burning media through STM32 stlink utility tool
猜你喜欢
![[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality](/img/12/1763571a99e6ef15fb7f9512c54e9b.png)
[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality

Read and upgrade st-link chip information and SWD burning media through STM32 stlink utility tool

Arduino IDE for raspberry PI Pico development firmware localization installation tutorial

2022-07-19: all factors of F (I): I are added up after each factor is squared. For example, f (10) = 1 square + 2 square + 5 square + 10 square = 1 + 4 + 25 + 100 = 130.

Review all frames before sum of SSM frames

Arduino + si5351 square wave generator

Brief understanding of operational amplifier

Selenium framework operation steelth.min.js file hides browser fingerprint features

Dc-2-range practice

Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
随机推荐
PHP record
Go multiplexing
2022-07-19: all factors of F (I): I are added up after each factor is squared. For example, f (10) = 1 square + 2 square + 5 square + 10 square = 1 + 4 + 25 + 100 = 130.
Matlab for circular pit
Backtracking to solve subset problem
[stm32f103rct6] motor PWM drive module idea and code
Query the information of students whose grades are above 80
Learning record XIII
NVM installation and use
Pypi counts the number of Downloads
Dynamic planning of force buckle punch in summary
Learning record 12
DOM node type
[stm32f103rct6] can communication
Resolve the error: org.apache.ibatis.binding.bindingexception
Mark down learning
From input URL to page presentation
JS foundation -- regular expression
JS written test question -- prototype, new, this comprehensive question
Selenium framework operation steelth.min.js file hides browser fingerprint features