Party All the Time
题目链接:HDU - 4355#include <bits/stdc++.h>
#define eps 1e-6//注意了精度高了会T;
using namespace std;
int N;
double x[50010], w[50010];
double cal(double a){
double ans=0.0;
int i=0;
for(i=0; i<N; i++){
ans+=pow(fabs(x[i]-a), 3)*w[i];
}
return ans;
}
int main(){
int T, cas=0;
scanf("%d", &T);
while(T--){
cas++;
scanf("%d", &N);
for(int i=0; i<N; i++){
scanf("%lf%lf", &x[i], &w[i]);
}
double l=x[0], r=x[N-1];
while(r-l>eps){
double mid=l+(r-l)/3;
double midd=r-(r-l)/3;
if(cal(mid)>cal(midd)) l=mid;
else r=midd;
}
double temp=cal(l);
long long ans=(int)temp;
if(temp-ans>=0.5) ans++;
printf("Case #%d: %lld\n", cas, ans);
}
return 0;
}
408




被折叠的 条评论
为什么被折叠?



