Codeforces 429D Tricky Function

Source: Internet
Author: User

Codeforces 429D Tricky Function

This is equivalent to I representing the X axis, sum [I] representing the Y axis, sum [I] representing the sum of the previous I numbers

Calculate the distance between the minimum two points.

The so-called question is the question that suddenly becomes enlightened after reading the question, that is, the distance between j-> I first calculated during calculation,

# Include

 
  
# Include

  
   
# Include

   
    
Using namespace std; typedef long ll; # define N 11111ll a [N]; ll sum [N]; int ans; int main () {int n; sum [0] = 0; scanf ("% d", & n); for (int I = 1; I <= n; I ++) {scanf ("I64d", & a [I]); sum [I] = sum [I-1] + a [I];} ans = a [2] * a [2] + 1; for (ll I = 1; I

    
     
Ans) break; // so importantll t = ans; for (int j = I + 1; j <= n; j ++) {t = min (t, (sum [j]-sum [j-I]) * (sum [j]-sum [j-I]);} ans = min (ans, t + I * I);} cout <

     

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.