Skip to content

announce the list: dice roll sequence GCD-sequence all in one gun

Dice Roll Sequence

greedy.

GCD-sequence

implementation. loop the array and stop till meet the first point, suppose is i. and we can remove i , i-1 or i+1. And then we check if the remain is satisfy the conditions.

But i have a another way. As we want to keep it be non-decreasing, it means that every time we check the gcd of two numbers, besides the origin the gcd that inherited by the preform numbers, it should at least be hu zhi de after divide by the preform gcd.

All-in-one Gun

To my surprised hat we should consider preview sum and suffix sum in the problem. At begin, we divide. Based on the greedy, when we loop the array, at every position, we check the preview smallest number, suppose a and suffix biggest number, suppose b. And when the a>b, that means there is any necessary to swap, otherwise we swap them. That's interesting.