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