EOJ2018.10 month (B math + thinking problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.