Party all the time
Time limit:6000/2000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 4282 Accepted Submission (s): 1355
Problem DescriptionIn The Dark forest, there is a fairy kingdom where all the spirits would go together and celebrate the H Arvest every year. But there are one thing you may not know the they hate walking so much, they would prefer to stay at home if they need To walk a long-to. According to our observation,a spirit weighing W would increase its unhappyness for s3*w units If it walks a distance of S Kilometers.
Now give you every spirit's weight and location,find the best place to celebrate the harvest which make the sum of unhappy Ness of every spirit the least.
Inputthe first line of the input is the number T (T<=20), which is the number of cases followed. The first line of all case consists of one integer N (1<=n<=50000), indicating the number of spirits. Then comes N lines in the order, x[i]<=x[i+1] for all I (1<=i<n). The i-th line contains both real number:xi,wi, representing the location and the weight of the i-th. (|xi|<=106, 0<wi<15)
Outputfor Each test case, click Output a line which are "case #X: Y", X means the number of the "the" and Y means the Minimum sum of unhappyness which is rounded to the nearest integer.
Sample Input140.6 53.9 105.1 78.4 10
Sample outputcase #1:832
Author[email Protected]_goldfinger
Source2012 multi-university Training Contest 6 title: n the person to be in a certain segment of the party, this N person began to have a coordinate XI, a weight of WI, everyone to the location distance set to S. Let you count everyone to the s^3*w and the smallest of the position. Find the smallest and. Problem Solving Ideas: Apply three-point solution.
#include <bits/stdc++.h>using namespace Std;typedef long long int;const int maxn=1e5+200;int n;const int mv=1e6; Const double eps=1e-2;struct spirit{double x; Double W;} SPIRITS[5*MAXN];d ouble Abs (double xx) {return xx>0?xx:-xx;} Double Pow (double x,int nn) {double ret=1.0; for (int i=1;i<=nn;i++) ret*=x; return ret;} Double cal (double xx) {double sum=0; for (int i=1;i<=n;i++) {Sum+=pow (Abs (SPIRITS[I].X-XX), 3) *SPIRITS[I].W; } return sum;} Double Three_div (double l,double R) {//three min for maximum double mid= (l+r)/2,mid_l= (L+mid)/2; while (Abs (Cal (mid)-cal (mid_l)) >eps) {//conditions should be subject to availability mid= (R+L)/2.0; Mid_l= (L+MID)/2.0; if (Cal (mid) >cal (mid_l)) {r=mid; }else{l=mid_l; }} return mid; Gets the coordinate position of the maximum value}int main () {int t,cnt=0; scanf ("%d", &t); Double min_v=mv* ( -1.0), max_v=mv*1.0; while (t--) {scanf ("%d", &n); for (int i=1;i<=n;i++) {scanf ("%lf%lf ", &SPIRITS[I].X,&SPIRITS[I].W); } double Xx=three_div (MIN_V,MAX_V); printf ("Case #%d:%lld\n", ++cnt, (INT) (Cal (XX) +0.5)); } return 0;}
HDU 4355--party all the time —————— "three minutes to find the smallest and"