HDU 4355 points on the axis to make the si^3*wi minimum and-floating point three points

Source: Internet
Author: User

Test instructions: There are n points on a axis, now we need to find a point to all points of the distance si cubic times the right of the point of the WI and the smallest

Analysis: three points. Two or three points of a floating-point number can be used to limit the number of lookups by a single digit. Tle several times, the number of searches from 10000 to 100 on the past, originally thought the data range is large, 100 accuracy is not enough.

Code:

#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include < Cstring> #define EPS 1e-8#define eps2 1e-5#define INF  100000000000007using namespace Std;int t,n;double x[100005] , w[100005];d ouble ans;long long ans1;double dis (double a,double b) {if (a>b) {double tmp=a;a=b;b=tmp;} Return Pow ((b-a), 3);} Double ll (double a) {double sum=0;for (int i=0;i<n;i++) {Sum+=dis (A,x[i]) *w[i];} return sum;} Double find (double left,double right) {double l=left,r=right;double ans1,ans2;for (int i=0;i<100;i++) {double mid1= (l +R)/2.0;double mid2= (mid1+r)/2.0;ans1=ll (MID1), Ans2=ll (MID2), if (ll (MID1) <ll (MID2))  r=mid2;else  l= MID1;} return ans1;} int main () {scanf ("%d", &t), for (int cas=1;cas<=t;cas++) {scanf ("%d", &n), and for (int i=0;i<n;i++) scanf ("%lf %lf ", &x[i],&w[i]); Ans=find (x[0],x[n-1]);    ans1= (Long long int) (ans+0.5);p rintf ("Case #%d:%i64d\n", cas,ans1);}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4355 points on the axis to make the si^3*wi minimum and-floating point three points

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.