HDU 5073 Galaxy

Source: Internet
Author: User

Test instructions is a given n point, which allows a point p to be found to minimize the Sigma ((A[i]-p) ^ 2), where A[i] represents the position of the point I. There are k points which don't count.

Idea: Found this problem is actually seeking n-k a point variance.

So push the formula:

Sigma ((A[i]-p) ^ 2)

= Sigma (a[i]^2 + p^2-2*a[i]*p)

= Sigma (a[i]^2 + p^2))-Sigma (2*a[i]*p)

= Sigma (a[i]^2) + (n-k) * (p^2)-2*p*sigma (A[i])//Because Sigma asks for the number of n-k and

= Sum2[i] + (n-k) * (p^2)-2*p*sum[i]

Here Sum2[i] is the sum of the preceding number of squares, sum[i] is the sum of the number of previous I. P is the average of this interval of length n-k. It can be obtained once the pretreatment. So the total time complexity is also O (n)

HDU 5073 Galaxy

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.