Portal: Problem B
Https://www.cnblogs.com/violet-acmer/p/9739115.html
Test instructions
Find the smallest sequence s with sub-sequence A, and the sequence S is the p -Moganshan sequence.
Exercises
It is easy to think of P = max_ai+1, and a[1] corresponds to s[1], otherwise it needs to be in a[1] before adding other numbers to make a[1]-> a s[i], certainly longer than the non-additive sequence.
Traversal a[] Array, divided into three cases of discussion
①a[i] > A[i-1]
In this case, a[i-1]--a[i] is a continuous sequence in s, res + = A[i]-a[i-1].
②a[i] < a[i-1]
This condition corresponds to the case of A[i], P-and a[i-1], res + = P-a[i]+a[i-1].
③a[i] = = A[i-1]
Equal, just a period of difference, res + = P.
Note that the result will be a long long type.
AC Code:
1#include <iostream>2#include <cstdio>3 using namespacestd;4 #definell Long Long5 Const intmaxn=2e5+ -;6 7 intA[MAXN];8 9 intMain ()Ten { One intN; Ascanf"%d",&n); - for(intI=1; I <= n;++i) -scanf"%d", A +i); thell res=1; - intp=0; - for(intI=1; I <= n;++i) -p=Max (p,a[i]); +p++; - for(intI=2; I <= n;++i) + { A if(A[i] > a[i-1]) atRes + = a[i]-a[i-1]; - Else if(A[i] < a[i-1]) - { - intk=a[i-1]/p; -Res + = ((k +1) *p-a[i-1])+A[i]; - } in Else -Res + =p; to } +printf"%lld\n", res); -}View Code
EOJ2018.10 month (B math + thinking problem)