记录编号 415294 评测结果 AAAAAAAAAAAAAAAATATT
题目名称 [NOI 2012]骑行川藏 最终得分 85
用户昵称 Gravatarsxysxy 是否通过 未通过
代码语言 C++ 运行时间 3.409 s
提交时间 2017-06-16 10:18:46 内存使用 0.67 MiB
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdarg>
#include <list>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
namespace solve{
  
const int MAXN = 10003;
int n;
double E, s[MAXN], k[MAXN], v[MAXN], vp[MAXN];
double maxv[MAXN];
const double eps = 1e-13;
double getv(int pos, double lambda){
  double l = vp[pos], r = maxv[pos];
  while(r - l >= eps){
    double m = (l+r)/2;
    if(fabs(m-l) < eps || fabs(m-r) < eps)break;
    if(m*m*2*lambda*k[pos]*(m-vp[pos])+1 > 0)l = m;
    else r = m;
  }
  return l;
}
double get_sum(){
  double ans = 0;
  for(int i = 1; i <= n; i++)
    ans += s[i]*k[i]*(v[i]-vp[i])*(v[i]-vp[i]);
  return ans-E;
}
void calc_lambda(double l, double r){
  while(r - l >= eps){
    double m = (l+r)/2;
    if(fabs(m-l) < eps || fabs(m-r) < eps)break;
    for(int i = 1; i <= n; i++)
      v[i] = getv(i, m);
    double t = get_sum();
    if(t > 0)r = m;
    else l = m;
  }
}

}
int main(){
  freopen("bicycling.in", "r", stdin);
  freopen("bicycling.out", "w", stdout);
  scanf("%d %lf", &solve::n, &solve::E);
  for(int i = 1; i <= solve::n; i++){
    scanf("%lf %lf %lf", solve::s+i, solve::k+i, solve::vp+i);
    solve::maxv[i] = solve::vp[i]+sqrt(solve::E/solve::s[i]/solve::k[i]);
  }
  solve::calc_lambda(-1000, -solve::eps);
  double ans = 0;
  for(int i = 1; i <= solve::n; i++)
    ans += solve::s[i]/solve::v[i];
  printf("%.8lf\n", ans);
  return 0;
}